[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

.Net Threading Wait/Busy Form

Posted on 2013-06-07
11
Medium Priority
?
768 Views
Last Modified: 2013-07-12
I want to display a animated gif while some data is being loaded in the background on its own thread.  the code works and loads the image, but after running the function a couple time I get "Process cannot access a file because it is being used by another process".  I believe that it has something to do with how I am using the gif file.  any help to fix this would be appreciated.

---:[My Class Code For Threading]:---

Public Class clsOPAWaitScreen
    Dim Thread1 As System.Threading.Thread
    Dim m_intTop As Integer
    Dim m_intLeft As Integer
    Dim objPlsWait As New frmPleaseWait

    Public Sub ShowWaitScreen(ByVal strMessage As String, ByVal p_intTop As Integer, ByVal p_intLeft As Integer)
        Thread1 = New System.Threading.Thread(AddressOf MakeItHappen)
        Thread1.Name = strMessage ' Name is being used here to pass parameters. (In this case a message.)
        m_intTop = p_intTop
        m_intLeft = p_intLeft
        Thread1.Start()
    End Sub
    Private Sub MakeItHappen(ByVal strMsg As String)
        Try
            objPlsWait.SetLocation(m_intTop, m_intLeft)
            objPlsWait.SetMessage(System.Threading.Thread.CurrentThread.Name)
            objPlsWait.ShowDialog()
        Catch ex As Exception
            ' Do nothing supress error.
        Finally
            If objPlsWait IsNot Nothing Then objPlsWait.Dispose() : objPlsWait = Nothing
        End Try
    End Sub
    Public Sub CloseWaitScreen()
        'objPlsWait.Close()
        Thread1.Abort(Nothing) ' Makes the form go away.
    End Sub
End Class


---:[My Wait Processing Form]:---

Public Class frmPleaseWait
    Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        'Me.PictureBox1.Image = ImageList1.Images(0)
        PictureBox1.Image = My.Resources.WaitProcessing1
    End Sub

    Public Sub SetMessage(ByVal strMessage As String)
        lblMsg.Text = strMessage
    End Sub

    Public Sub SetLocation(ByVal p_intTop As Integer, ByVal p_intLeft As Integer)
        p_intLeft = p_intLeft - CInt(Me.Width / 2)
        p_intTop = p_intTop - CInt(Me.Height / 2)
        Me.Location = New Point(p_intLeft, p_intTop)
    End Sub
End Class


---:[How I call the Code]:---

Dim objPlsWait As New clsOPAWaitScreen
objPlsWait.ShowWaitScreen("Please wait...", intTop, intLeft)

            '---:[Run Query]:---        

objPlsWait.CloseWaitScreen()
objPlsWait = Nothing



Thanks
Ian
0
Comment
Question by:mcsdguyian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 10

Expert Comment

by:adriankohws
ID: 39231050
I would suggest you just create a physical form for the waitscreen with the animated GIF.
So before you execute whatever you need to execute, show that form and perform an
Application.DoEvents(). Once the executions are done, then you display message and then close the form.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39231614
Nothing in the code you posted pops out as being a potential cause for that error.

What are you doing in " '---:[Run Query]:---"?
0
 

Author Comment

by:mcsdguyian
ID: 39235166
I am just executing some SQL stored procedures that do some long database updates.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39238957
Does the error go away if you do not use the image?
0
 

Author Comment

by:mcsdguyian
ID: 39239359
I recently re installed my computer and I didn't have service pack1 on Visual studio 2010.  I installed that and I haven't seen the error.  

When I run the program from another computer with out VS2010, I get the following error "System.Threading.ThreadAbortException: Thread was being aborted." and sometimes the image has a Big Red "X" through it.  

When running it on my computer I was under the impression that it was the image.  Now after removing the image and running it on a client computer I have more information in the form of error messages.  

Its not the image, but has something else to do with threading.

There is a full error detail I am posting below if it helps.

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Threading.ThreadAbortException: Thread was being aborted.
   at System.Windows.Forms.UnsafeNativeMethods.SetWindowLongPtr32(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
   at System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
   at System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle, Boolean assignUniqueID)
   at System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle)
   at System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3643 (GDR.050727-3600)
    CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Commissions
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/QCSProgs/Commissions/Commissions.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 8.0.0.0
    Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3644 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3645 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3644 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Transactions
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.


Thanks for any help you can provide
0
 

Author Comment

by:mcsdguyian
ID: 39239389
adriankohws,

In response to your answer.  I did initially try this, but could not get the animated gif to run animated.  I was also trying to keep the waitform on top  and was having to run a timer to check that it was on top and move it to the top if needed.

Have you tried this with success on animated Gif files and kept the waitform on top without losing it behind another form?

thanks
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39239409
Have you considered using a backgroundworker?
0
 

Author Comment

by:mcsdguyian
ID: 39239476
I really have very little experience with backgroundworkers and threading.  What would the advantage be? do you have any code or point to a good resource?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 39239535
Advantage would be getting rid of threading issues

http://www.java2s.com/Code/VB/GUI/BackgroundWorkerDemo.htm
0
 
LVL 10

Expert Comment

by:adriankohws
ID: 39241140
" I did initially try this, but could not get the animated gif to run animated.  I was also trying to keep the waitform on top  and was having to run a timer to check that it was on top and move it to the top if needed."

I kind of agreed, I tried that before, it's moving, but not very smooth.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39241354
If the animated GIF is not animating smoothly (or at all) it means you haven't properly moved the "work" to a background thread...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question