Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Multi-threading Debugging Enhancements in Visual Studio 2008

Download

Right click “Save as…”

Author: Hi, I am Daniel Moth Smiley

Introduction: They say debugging is a skill and that threading is hard so when you put the two together, you have a challenge. Visual Studio 2008 has added a handful of small new featurettes to help with that. Watch the 15' video for more.

Video download: Click on the image to play the video (from a streaming file). If you'd prefer to download the wmv packaged in a zip file, you may do so here.

Tags:

Follow the Discussion

  • Luis Gonzalo Cardenas Ojedaluiscperu Luisc
    Good video Daniel !!:

    I was wondering if your example code is avalaible for analysis.

    Thanks in advance.

  • Glad you enjoyed it luiscperu (and I see you joined channel9 today - welcome!) Big Smile

    Typically I make sure to show all the code in my videos so they can be easily replicated. It is only thru typing it in yourself you get to "feel" the code. Having said that, I still had this project kicking around so I've uploaded here for you:
    http://www.danielmoth.com/Blog/ThreadPlay.zip

  • Luis Gonzalo Cardenas Ojedaluiscperu Luisc
    Thanks Daniel.
  • Pleasure luiscperu.
  • Hello,

    I've included the code for a class that I'm struggling with.
    (I've omitted the FormStatus object, but any form with a lblStatus label would do).

    The purpose of the class is to display a StatusForm on a separate thread.

    The StatusForm has a rotating logo, and a label that can get updated to reflect status on the main thread...

    Sample usage from some class, or form...(within a loop or long running routine)

    'Would be called to display a "TopMost" form indicating status..
    ClsAsyncStatusDisplay.DisplayStatus("Doing something...")
    ClsAsyncStatusDisplay.DisplayStatus("25% Complete...")
    ClsAsyncStatusDisplay.DisplayStatus("50% Complete...")

    'Would be called to hide the form from view
    ClsAsyncStatusDisplay.HideStatus()

    My class works 99% of the time, but occassionally the class "locks up"...

    I'm open to ANY suggestions! -- I'm sure there's a much better tecnique than this...

    Thanks.






    Option
    Strict On
    Option
    Explicit On

    Public Class ClsAsyncStatusDisplay

    Private Shared _thisInstance As ClsAsyncStatusDisplay

    Private Message As String = ""
    Private WithEvents StatusThread As System.Threading.Thread
    Private WithEvents StatusForm As FormStatus
    Private Delegate Sub SetTextCallback(ByVal [text] As String)

    Private _DelegateSetTextCallBack As New SetTextCallback(AddressOf SetText)

    Private Delegate Sub CloseFormCallBack()

    Private _DelegateCloseFormCallBack As New CloseFormCallBack(AddressOf CloseForm)

    Private Sub New()

    'Forces Singleton Class

    End Sub

    Public Shared Sub DisplayStatus(ByVal msg As String, Optional ByRef obj As Control = Nothing)

    If IsNothing(_thisInstance) Then

    _thisInstance = New ClsAsyncStatusDisplay

    End If

    If IsNothing(_thisInstance.StatusThread) Then

    _thisInstance.StatusThread = New System.Threading.Thread(AddressOf _thisInstance.ShowForm)

    System.Threading.Thread.Sleep(750) 'Don't display status unless outside process is taking almost 1 second to complete....

    _thisInstance.StatusThread.Start()

    ElseIf Not IsNothing(_thisInstance.StatusThread) And _thisInstance.StatusThread.ThreadState = Threading.ThreadState.Stopped Then

    _thisInstance.StatusThread = Nothing

    _thisInstance.StatusThread = New System.Threading.Thread(AddressOf _thisInstance.ShowForm)

    System.Threading.Thread.Sleep(750) 'Don't display status unless outside process is taking almost 1 second to complete....

    _thisInstance.StatusThread.Start()

    Else

    _thisInstance.SetText(msg)

    End If

    _thisInstance.Message = msg

    End Sub

    Public Shared Sub HideStatus()

    If Not IsNothing(_thisInstance.StatusForm) Then

    _thisInstance.CloseForm()

    End If

    End Sub

    Private Sub ShowForm()

    Try

    If IsNothing(_thisInstance.StatusForm) OrElse _thisInstance.StatusForm.IsDisposed Then

    _thisInstance.StatusForm = New FormStatus

    End If

    SetText(_thisInstance.Message)

    If _thisInstance.StatusForm.IsDisposed = False Then

    _thisInstance.StatusForm.ShowDialog()

    End If

    Catch ex As Exception

    'Do Nothin'

    Me.CloseForm()

    End Try

    End Sub

    Private Sub CloseForm()

    Try

    If _thisInstance.StatusForm.InvokeRequired Then

    _thisInstance.StatusForm.Invoke(_DelegateCloseFormCallBack)

    Else

    If Not IsNothing(_thisInstance.StatusForm) And Not _thisInstance.StatusForm.IsDisposed Then

    _thisInstance.StatusForm.Close()

    End If

    End If

    Catch ex As Exception

    'Do Nothin'

    End Try

    End Sub

    Private Sub SetText(ByVal [text] As String)

    Try

    If Not IsNothing(_thisInstance.StatusForm) AndAlso _thisInstance.StatusForm.Disposing = False AndAlso _thisInstance.StatusForm.IsDisposed = False Then

    ' InvokeRequired required compares the thread ID of the

    ' calling thread to the thread ID of the creating thread.

    ' If these threads are different, it returns true.

    If _thisInstance.StatusForm.lblStatus.InvokeRequired Then

    _thisInstance.StatusForm.lblStatus.Invoke(_DelegateSetTextCallBack, New Object() {[text]})

    Else

    _thisInstance.StatusForm.lblStatus.Text = [text]

    End If

    End If

    Catch ex As Exception

    'do nothin

    Me.CloseForm()

    End Try

    End Sub

    End Class

     

  • Hi Windsurfer

    Sorry to hear about your problem.

    You have confused this place (which is about that specific video on the top) with some kind of generic support forum (which this isn't).

    Please pick a more appropriate forum, starting here:
    http://forums.microsoft.com/MSDN/

    Good luck!

    Cheers
    Daniel
  • Daniel,

    Good sharing.  Thanks
  • kpresario, glad it was useful. Thanks for watching!

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.