A question of remoting

  • Thread starter Thread starter Jeff Yang
  • Start date Start date
J

Jeff Yang

when the client call a remote method,Whether the server will create a new
thread or not to complete the method?
My remote method will update the listView on the server,so I think if it is
performed in a new thread,then I should use listView's Invoke method,am I
right?
Thanks a lot!
 
I'm not sure but you can check it by getting the current thread id when the app starts and getting it again in the method. If they
are different then you will need to call invoke.
 
Thanks!
I have tried.and in the debug window,I find the method is in a new
thread.So,it seems the server has created a new thread to complete the call.
then still another question:
I find in my method,there is such codes:
listView1.Items[chnum].SubItems[3].Text="hahaha";
then I can't use invoke,and how can i deal with it?

Thanks!

Michael Culley said:
I'm not sure but you can check it by getting the current thread id when
the app starts and getting it again in the method. If they
 
Hi Jeff,

You can always check whether you need to Invoke() or not by checking the
listView's InvokeRequired property. As a rule, remoting requests are served
by threads on the thread pool, so you'll most likely need to use the
Control.Invoke mechanism.
 
Jeff,
I find in my method,there is such codes:
listView1.Items[chnum].SubItems[3].Text="hahaha";
then I can't use invoke,and how can i deal with it?

Actually, you can. Refactor your code a little bit to move all the
UI-related code to a separate private method (even if it would contain a
single line of code, that's OK). Define a delegate matching the method
signature (let's call it UiUpdateDelegate)

Then, replace the original code to the call to that private method that will
look like this:

if (!listView1.InvokeRequired)
{
DoUiUpdate(paramA, paramB);
}
else
{
listView1.Invoke(new UiUpdateDelegate(DoUiUpdate),
new object[] {paramA, paramB});
}


--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Jeff Yang said:
Thanks!
I have tried.and in the debug window,I find the method is in a new
thread.So,it seems the server has created a new thread to complete the call.
then still another question:
I find in my method,there is such codes:
listView1.Items[chnum].SubItems[3].Text="hahaha";
then I can't use invoke,and how can i deal with it?

Thanks!

Michael Culley said:
I'm not sure but you can check it by getting the current thread id when
the app starts and getting it again in the method. If they
 
Thanks Dmitriy Lapshin!
Both of your answers really help a lot!
Now I think I can manage it with no doubt. :)
 
Back
Top