Jump to content

  • Log In with Google      Sign In   
  • Create Account

Asynchronous functions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Chris_F   Members   -  Reputation: 2462

Like
-1Likes
Like

Posted 11 February 2012 - 02:18 AM

So I'm not particularly savvy with threading and async operations in C#, but I'm working on a mesh tool for my asset pipeline and would like to handle these things a little more elegantly. Particularly I'd like to maintain a responsive UI at all times and maybe even get some active feedback on what's going on. My first attempt was to make my loading function asynchronous.

public static void LoadObjectFileAsync(string filename, Action<Mesh> callback)
{
	BackgroundWorker bw = new BackgroundWorker();
	bw.DoWork += (object sender, DoWorkEventArgs e) =>
	{
		callback(LoadObjectFile(filename));
	};
	bw.RunWorkerAsync();
}

Unfortunately, if I try and do anything useful in the callback method, like update my UI I get a cross-thread operation error.

Sponsor:

#2 Washu   Senior Moderators   -  Reputation: 5423

Like
0Likes
Like

Posted 11 February 2012 - 04:42 AM

Controls have an Invoke method for cross thread calls.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS