Toad
Toad

Reputation: 115

Silverlight Threadpool

I have a question about threading in Silverlight. I come mainly from a winForms background and usually use the following wrapper class to do my threading:

http://msdn.microsoft.com/en-us/magazine/cc163644.aspx

It has worked for doing window development but I am not able to use it in Silverlight. The reason is because ExecutionContext is marked with the [SecurityCritical] attribute making it impossible to call from Silverlight.

Is there a similar wrapper class out there for Silverlight or is there a way I can get around this issue?

Thanks!

Upvotes: 1

Views: 282

Answers (3)

Vitaliy Gerasymiuk
Vitaliy Gerasymiuk

Reputation: 236

Rewrite existed code for using a "Task" (Task Link) or a BackgroundWorker (BackgroundWorker Link).

We should use a newest technologies, which give us a technological evolution.

Upvotes: 0

leon.io
leon.io

Reputation: 2824

Take a look at cancellation tokens (via the CancellationTokenSource) available only in SL5. It uses a similar mechanism as the one used in your MSDN mag ref.

This is a good 'how-to' article. Some MSDN References here, as well as a lengthy but great article here

All the best, and welcome to XAML programming :) You won't look back!

Upvotes: 0

Brian Gideon
Brian Gideon

Reputation: 48949

I would not use the class you cited even in a WinForm application. It still uses Thread.Abort which can (and probably would) corrupt the app domain. Instead, use the new Cancellation mechanisms in the Task Parallel Library. You will have to rethink your whole approach to cancelling the work items though. This is because you can no longer rely on forced termination and have to use cooperative termination instead. The advantage is that the later can be guaranteed to avoid corrupting the app domain.

Upvotes: 1

Related Questions