B
Brett Robichaud
I'm using an async delegate to spawn a thread and run some code. I also
specify an AsyncCallback to get notified when the thread completes. The
problem is that my callback is being called twice and I can't figure out
why. Here is a snippet of my code, the LoadImageThreadComplete() method is
being called twice even though LoadImage() is only ever called once. Any
ideas why?
delegate void LoadImageDelegate(string file);
private void LoadImage(string file)
{
LoadImageDelegate delg = new LoadImageDelegate(LoadImageThread);
delg.BeginInvoke(file, new AsyncCallback(LoadImageThreadComplete),
null);
}
private void LoadImageThread(string file)
{
Thread.Threading.Sleep(1000);
}
private void LoadImageThreadComplete(IAsyncResult ar)
{
((AsyncCallback)ar.AsyncState).EndInvoke(ar);
}
specify an AsyncCallback to get notified when the thread completes. The
problem is that my callback is being called twice and I can't figure out
why. Here is a snippet of my code, the LoadImageThreadComplete() method is
being called twice even though LoadImage() is only ever called once. Any
ideas why?
delegate void LoadImageDelegate(string file);
private void LoadImage(string file)
{
LoadImageDelegate delg = new LoadImageDelegate(LoadImageThread);
delg.BeginInvoke(file, new AsyncCallback(LoadImageThreadComplete),
null);
}
private void LoadImageThread(string file)
{
Thread.Threading.Sleep(1000);
}
private void LoadImageThreadComplete(IAsyncResult ar)
{
((AsyncCallback)ar.AsyncState).EndInvoke(ar);
}