control.invoke help

  • Thread starter Thread starter mak
  • Start date Start date
M

mak

hi guys!
I think that the solution of the problem might be control.invoke nut i
can't understand how it function...here's the problem.

I have a C# application with 3 buttons and one textbox. the first one,
Start Reading, whenever clicked creates a thread, readthread. The entry
point of this thread is a function named Readentrypoint. The function
calls a DLL function (listen) using dllImport attribute.
Now, listen function returns a string that I want to view in the
textbox. So I put this statement in the readentrypoint function:

textBox1.text = listen();


the compiler not returns any kind of error but at execution time it
fails with error like 0x37437, not exception anyway..

I think it's a problem with threading, maybe because i'm creating a
thread but the controls owns to the application main form....
however, I've search on msdn but I did'n find any kind of exemple.

Please, help me or tell me what I'm doing wrong!
thanx

marco
 
The textBox1 control was not created in the same thread that the
ReadEntryPoint method executes in, so you can't set it's properties like
that from inside the method. You have to marshal them to the thread that
created the textbox

Check out these methods in MSDN for more info:
Control.InvokeRequired
Control.Invoke
Control.BeginInvoke
Control.EndInvoke

/claes
 
thanx, I read the sample on msdn and I got through the problem, however
it needs always to create a function that fills the control and then
pass this function to the delegate, finally call the delegate from the
control with .invoke method.it's ok now, I only thought I could fill
the textbox directly...anyway.

thanx

marco
 
Back
Top