Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Asynchronous functions

4: Adsense

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   

3030
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.

#2 Washu   Senior Moderators   

7804
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.