Image visible during background process

D

Diego F.

Hello. I have a process that can take a long time and I'm trying to put an
animated gif while the user is waiting.

I added a panel with a picturebox with the image inside. The panel is not
visible when the application starts, but before the process, I make it
visible.

The problem is that while the long process is running, the image doesn't
appear. The panel is empty.

How can I ensure that the animated gif is shown?
 
R

rowe_newsgroups

Hello. I have a process that can take a long time and I'm trying to put an
animated gif while the user is waiting.

I added a panel with a picturebox with the image inside. The panel is not
visible when the application starts, but before the process, I make it
visible.

The problem is that while the long process is running, the image doesn't
appear. The panel is empty.

How can I ensure that the animated gif is shown?

--

Regards,

Diego F.

Are you running the "long process" on the main UI thread or on a
seperate thread?

Thanks,

Seth Rowe
 
D

Diego F.

rowe_newsgroups said:
Are you running the "long process" on the main UI thread or on a
seperate thread?

Thanks,

Seth Rowe

Actually I'm running that process in the main thread. I can run it in a
separate thread with the Backgroundworker, but then I need to stop the
execution until it's finished. How can I do that?
 
D

Diego F.

I found that code:

Private _dataLock As New ManualResetEvent(False)
Me.BackgroundWorker1.RunWorkerAsync()
_dataLock.WaitOne()

and in the DoWork method...
_dataLock.Set()

The problem is that the application stops completely and the gif animation
is not shown, so I'm in the same point again.
 
R

rowe_newsgroups

Actually I'm running that process in the main thread. I can run it in a
separate thread with the Backgroundworker, but then I need to stop the
execution until it's finished. How can I do that?

--

Regards,

Diego F.

I wouldn't use the BackGroundWorker, but thats just me. I would create
a class that wraps the method and contains a "WorkFinished" event that
fires when the task is done. Then you just have to instantiate the
class, subscribe to it's WorkFinished event, and call it's Begin()
method - the class will take care of spawning the new thread and will
notify you when it's done.

Something like this:

' Typed in message

Public Class MyThreadWrapper

public sub new()

end sub

public sub Begin()
Dim t as new thread(addressof DoTheWork)
' Set any necessary properties for the thread
t.Start()
end sub

private sub DoTheWork()
' Do the long process
RaiseEvent(WorkFinished(me, EventArgs.Empty))
end sub

public event WorkFinished as EventHandler

End Class

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top