Cutch

Cutch

  • NA
  • 14
  • 0

Invokng in C++

Jun 22 2008 5:42 PM
Okay,
I have two threads, the main thread with the form, and a background thread from a background worker.
I have to change a string variable declared in the main thread, from the background thread.
I've tried a bunch of different invoking methods, but i can't find any that work.

Any help would be great. Thanks in advance.

---------Edit---------
Okay i have gotten the invoke fine after some work and research,
    this->BeginInvoke(gcnew MyDelegate(this, &Form1::myMethod));
but now when it runs in the background thread, when it reaches the invoke line i get this error:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Invoke or BeginInvoke cannot be called on a control until the window handle has been created
.

I'm stumped I've looked around and can't find anything that solve this problem.

I have figured that the error is probably caused by the other thread which is running some other stuff, like painting a picture box, and refreshing the form.