Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 17:48

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C#] Cross-Threading ?

Discussion on [C#] Cross-Threading ? within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
Atheuz's Avatar
 
elite*gold: 81
Join Date: Jul 2005
Posts: 1,921
Received Thanks: 2,239
[C#] Cross-Threading ?

Hello,

Is there a flag or whatever that lets me use crossthreading freely? Without the help of a Workerthread. Whenever I try to change a variable it doesn't let me because Crossthreading isn't safe (eg. accessing the variables from other threads), but It's also hard to find a solution for this.
I'm starting another thread that contains a function to download the source code of another page and process the wanted information into variables, however I cannot do that with a thread. The only solution I could think of right now would be to save everything into a file and then let the program red it on the end of the batch. Any solutions?
Atheuz is offline  
Old 10/11/2008, 17:39   #2


 
Cholik's Avatar
 
elite*gold: 4
Join Date: Aug 2008
Posts: 6,786
Received Thanks: 4,992
Crossthreadexceptions should only be a problem when working with Forms in .NET right ?
Mh I think I remember that you had to invoke the functions of another thread before you could use them.
Although I can't help you directly with that try to find some example at

I'll move this to epvp*coders. They'll be able to help you with this. I guess we got a lot of C# coders in here.

#moved
Cholik is offline  
Old 10/11/2008, 18:01   #3
 
elite*gold: 20
Join Date: Sep 2006
Posts: 1,100
Received Thanks: 184
How about using shared memory :-)?
I think this can be done in C#
Bot_interesierter is offline  
Old 10/11/2008, 20:31   #4
 
Atheuz's Avatar
 
elite*gold: 81
Join Date: Jul 2005
Posts: 1,921
Received Thanks: 2,239
Quote:
Originally Posted by al_j View Post
Crossthreadexceptions should only be a problem when working with Forms in .NET right ?
Mh I think I remember that you had to invoke the functions of another thread before you could use them.
Although I can't help you directly with that try to find some example at

I'll move this to epvp*coders. They'll be able to help you with this. I guess we got a lot of C# coders in here.

#moved
It is, however even trying to this
string mytextbox = textBox1.Text;
and to change it lateron as mytextbox during the thread will also result in a
crossthread exception. And appartly I also cannot invoke functions of a different thread, without having to stop the current thread first.

Quote:
How about using shared memory :-)?
Explain.
Atheuz is offline  
Old 10/12/2008, 00:15   #5
 
elite*gold: 20
Join Date: Sep 2006
Posts: 1,100
Received Thanks: 184
You put the var in a shared memory section so every thread can access it, I'm not shure if it works, it's just an idea :-)
Bot_interesierter is offline  
Old 10/13/2008, 16:19   #6
 
elite*gold: 0
Join Date: Oct 2005
Posts: 201
Received Thanks: 23
you cannot access any part of the gui from another thread.
use Control.Invoke if you want to change the gui from a different thread.

please add some example code, its hard to help you without any code.
mondesser is offline  
Old 10/13/2008, 16:22   #7
 
Atheuz's Avatar
 
elite*gold: 81
Join Date: Jul 2005
Posts: 1,921
Received Thanks: 2,239
Quote:
Originally Posted by mondesser View Post
you cannot access any part of the gui from another thread.
use Control.Invoke if you want to change the gui from a different thread.

please add some example code, its hard to help you without any code.
Doesn't that method require a Worker Thread?
Atheuz is offline  
Old 10/14/2008, 08:41   #8
 
elite*gold: 0
Join Date: Oct 2005
Posts: 201
Received Thanks: 23
As far as i understood, you want a thread, that does something and then reports back to the gui.

you can:
-throw an event from your thread and catch it in the gui.
But you still have to call Invoke in the event handler.

-define a function in the gui class that does all the changes to the gui and invokes itself if an invoke is required, then call this function from the thread:
Code:
delegate void UpdateGuiDelegate();
public void UpdateGui()
{
  if (this.InvokeRequired)
  {
     UpdateGuiDelegate del = new UpdateGuiDelegate(AddressOf UpdateGui); //AddressOf is vb.net syntax, i forgot the C# syntax ^^
     this.Invoke(del);
  }
  else
  {
     //do your gui work here
  }
}
Invoke is a synchronous call, so in any case your thread will wait for the gui to finish its job. If you don't want that, you can call Control.BeginInvoke which is an asynchronous call.
mondesser is offline  
Reply


Similar Threads Similar Threads
Vke Cross fire acc
09/15/2010 - CrossFire Trading - 13 Replies
Hi ich vke hier meinen Cf acc für 10€ psc oder E*gold 993 ZP sind vorhanden und 859 BP Z8Games ? Home of the Best Free MMO Games - Clans - Character Details Pn me oder poste hier MfG ReMiXx
[Release]Make the threading system better.[5165 NewestCOServer]
09/13/2010 - CO2 PServer Guides & Releases - 10 Replies
Okay so, I was bored so I thought I would release some easy shiz. Credits to Impulse for his Thread.cs :) Goto Program.cs find Console.WriteLine("The server is ready for connections."); abit under that is the threading system. It's like
[C++] Problem with threading
05/17/2009 - CO2 Programming - 2 Replies
Actually the problem is more like with passing a function as pointer to the CreateThread or _beginthreadex, BOOL Connect() { if(m_Enabled != TRUE) return FALSE; sockaddr_in addr; addr.sin_family = AF_INET;
Something cross in my mind (lol)
11/17/2008 - Perfect World - 6 Replies
Well, I was thinking something about hacking idea in PW that make's me curios. So I want to ask some question (I hope someone can ask about this) 1. Is there any possibilities changing the Skill Range value(UsingCE ) (Like Archers skill). So job like Mage/FX can shoot longer distance?, Well My tought tell me it's probably server side (but i never tried to find the value/pointer anyway). 2. Suppose we can change the value/pointer of range/distance skill. it's there any possibilities we can...



All times are GMT +2. The time now is 17:48.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.