You may use a BackgroundWorker
to do the operation that you need in different thread like the following :
BackgroundWorker bgw;
public Form1()
{
InitializeComponent();
bgw = new BackgroundWorker();
bgw.DoWork += bgw_DoWork;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
bgw.RunWorkerAsync(s);
}
}
Also for your issue “cross thread operation”, try to use the Invoke
Method like this :
void bgw_DoWork(object sender, DoWorkEventArgs e)
{
Invoke(new Action<object>((args) =>
{
string[] files = (string[])args;
}), e.Argument);
}
Its better to check if the dropped items are files using GetDataPresent
like above.
3
solved Issue with drag and drop