1

I am using 3rd party library and some of the functions of the library take a long time to execute so I want to display a "Please Wait" dialog while the functions are busy.

Normally I would do something like this:

Thread longTask = new Thread (new ThreadStart(LongTask)); longTask.IsBackgroud = true; longTask.Start(); pleaseWaitForm = new PleasWaitForm ("Please wait for task to complete"); pleaseWaitForm.ShowDialog(); void LongTask() { // Do time consuming work here pleaseWaitForm.CanCloseFlag = true; } 

Unfortunately the 3rd party library is not thread-safe. Any workarounds? Is there any way of managing the Dialog Box as a background task?

2
  • 2
    What do you mean it isn't thread safe? It doesn't seem like your problem is related to this. Could you please elaborate. Commented Nov 16, 2009 at 19:21
  • If it's not thread-safe then it just means that it can't be, reliably, used by more than one thread at a time. It seems you are running a single background thread, so it should be fine. Are you getting some kind of error/race condition that led you to second-guess your design? Commented Nov 16, 2009 at 19:34

3 Answers 3

2

I think you are misunderstanding what "thread safe" means. If you are going to be calling methods/properties of your 3rd party component only from single thread, the component does not have to be thread safe. See this article.

Furthermore, I would suggest you use a background worker class in this case.

HTH

Sign up to request clarification or add additional context in comments.

Comments

1

You pretty much need to build your own dialog box.

One option is to poll your completed flag in a timer or the like.

Yet another option is to let the form "own" the task and use a BackgroundWorker for progress and completion notification.

Comments

0

Suppose you have a method, LongTask, and it is not thread safe. If that method is running and it does not need any shared variables, then you can simply wrap it around a BackgroundWorker and update the "please wait" screen the moment the task finishes.

If a certain method is not thread safe, that can still mean it is safe to use it in a thread, it just depends whether it runs multiple times asynchronously (danger!) or synchronously (not a problem).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.