1

i have used this code:

private void bgworker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    Close();
}

and in form closing:

private void Form_FormClosing(object sender, FormClosingEventArgs e)
{
    TopMost = false;
    do { ++Top; Application.DoEvents(); Thread.Sleep(5); }
    while (Top != r.Bottom);
}

i have this error: "A callback was made on a garbage collected delegate of type 'System.Windows.Forms!System.Windows.Forms.NativeMethods+WndProc::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called."

Rabee Alrabee
  • 95
  • 1
  • 7
  • Take a look at [this](http://blog.codinghorror.com/is-doevents-evil/) post about the "evil" DoEvents, and try rewrite your code in a way you can get rid of it. – Alessandro D'Andria Jun 29 '14 at 22:58
  • thanks to all i've made ​​the code in form closing comment, but became elsewhere, look to this: http://im77.gulfup.com/dVDmwS.jpg i was using this code to run single instance of an application: http://stackoverflow.com/a/12340210/2566731 – Rabee Alrabee Jun 29 '14 at 23:13
  • Please explain what do You want to achieve with the code in `Form_FormClosing` method. Please also take a look at this link for more detailed description why You typically shouldn't use `DoEvents` method: http://stackoverflow.com/questions/5181777/use-of-application-doevents. – Lukasz M Jun 29 '14 at 23:13

0 Answers0