Author:水如烟
Namespace
LzmTW.uSystem.uWindows.uForms
Public Class ProgressFormHelper
Private Sub New ()
End Sub
Private Shared gForm As ProgressForm
Private Shared gInternalSyncObject As Object
Private Shared gIsShowing As Boolean = False
Private Shared ReadOnly Property InternalSyncObject() As Object
Get
If gInternalSyncObject Is Nothing Then
Dim tmpObj As New Object
System.Threading.Interlocked.CompareExchange(gInternalSyncObject, tmpObj, Nothing )
End If
Return gInternalSyncObject
End Get
End Property
Private Shared Function CreateInstance() As ProgressForm
SyncLock InternalSyncObject
If gForm Is Nothing OrElse gForm.IsDisposed Then
gForm = New ProgressForm
End If
End SyncLock
Return gForm
End Function
Public Shared Sub Show( ByVal style As ProgressFormStyle)
CreateInstance()
gForm.Show(style)
gIsShowing = True
End Sub
Public Shared Sub Show( ByVal action As Threading.ThreadStart, ByVal style As ProgressFormStyle)
CreateInstance()
gForm.Show(action, style)
gIsShowing = True
End Sub
Public Shared Sub Show( ByVal action As Threading.ThreadStart, ByVal ctr As Object , ByVal style As ProgressFormStyle)
CreateInstance()
gForm.Show(action, ctr, style)
gIsShowing = True
End Sub
Public Shared Sub Show( ByVal action As Threading.ThreadStart, ByVal ctr As Object , ByVal actionInstance As Object , ByVal style As ProgressFormStyle)
CreateInstance()
gForm.Show(action, ctr, actionInstance, style)
gIsShowing = True
End Sub
Public Shared Sub Close()
If gForm IsNot Nothing AndAlso Not gForm.IsDisposed Then
gForm.Close()
gIsShowing = False
End If
End Sub
Public Shared Sub SendMessage( ByVal s As String )
If gIsShowing Then uThreading.CrossThread.SetControlPropertyValue(gForm.MessageLabel, " Text " , s, Nothing )
End Sub
Public Shared Sub SendMessage( ByVal format As String , ByVal args() As Object )
SendMessage(uString.Format( format , args))
End Sub
Public Shared Sub SetText( ByVal s As String )
If gIsShowing Then uThreading.CrossThread.SetControlPropertyValue(gForm, " Text " , s, Nothing )
End Sub
Public Shared Sub SetText( ByVal format As String , ByVal args() As Object )
SetText(uString.Format( format , args))
End Sub
End Class
Public Enum ProgressFormStyle
OnlyMessage
ProgressWithCancel
ProgressWithNoCancel
End Enum
Friend Enum ProgressFormActionResult
Finish
Cancel
End Enum
End Namespace
Public Class ProgressFormHelper
Private Sub New ()
End Sub
Private Shared gForm As ProgressForm
Private Shared gInternalSyncObject As Object
Private Shared gIsShowing As Boolean = False
Private Shared ReadOnly Property InternalSyncObject() As Object
Get
If gInternalSyncObject Is Nothing Then
Dim tmpObj As New Object
System.Threading.Interlocked.CompareExchange(gInternalSyncObject, tmpObj, Nothing )
End If
Return gInternalSyncObject
End Get
End Property
Private Shared Function CreateInstance() As ProgressForm
SyncLock InternalSyncObject
If gForm Is Nothing OrElse gForm.IsDisposed Then
gForm = New ProgressForm
End If
End SyncLock
Return gForm
End Function
Public Shared Sub Show( ByVal style As ProgressFormStyle)
CreateInstance()
gForm.Show(style)
gIsShowing = True
End Sub
Public Shared Sub Show( ByVal action As Threading.ThreadStart, ByVal style As ProgressFormStyle)
CreateInstance()
gForm.Show(action, style)
gIsShowing = True
End Sub
Public Shared Sub Show( ByVal action As Threading.ThreadStart, ByVal ctr As Object , ByVal style As ProgressFormStyle)
CreateInstance()
gForm.Show(action, ctr, style)
gIsShowing = True
End Sub
Public Shared Sub Show( ByVal action As Threading.ThreadStart, ByVal ctr As Object , ByVal actionInstance As Object , ByVal style As ProgressFormStyle)
CreateInstance()
gForm.Show(action, ctr, actionInstance, style)
gIsShowing = True
End Sub
Public Shared Sub Close()
If gForm IsNot Nothing AndAlso Not gForm.IsDisposed Then
gForm.Close()
gIsShowing = False
End If
End Sub
Public Shared Sub SendMessage( ByVal s As String )
If gIsShowing Then uThreading.CrossThread.SetControlPropertyValue(gForm.MessageLabel, " Text " , s, Nothing )
End Sub
Public Shared Sub SendMessage( ByVal format As String , ByVal args() As Object )
SendMessage(uString.Format( format , args))
End Sub
Public Shared Sub SetText( ByVal s As String )
If gIsShowing Then uThreading.CrossThread.SetControlPropertyValue(gForm, " Text " , s, Nothing )
End Sub
Public Shared Sub SetText( ByVal format As String , ByVal args() As Object )
SetText(uString.Format( format , args))
End Sub
End Class
Public Enum ProgressFormStyle
OnlyMessage
ProgressWithCancel
ProgressWithNoCancel
End Enum
Friend Enum ProgressFormActionResult
Finish
Cancel
End Enum
End Namespace