Dear ng,
i have developed a winforms application with vs2005.
An progress from with a animation and a timer is shown while the
application is working.
The trouble is, that often a ThreadAbordException occurs and i can not
identify
whats the reason is.
Can somebody help, please?
Thank you very much
Michael
--##################################################
following code i use:
--##################################
Private Sub tspProgress_VisibleChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tspProgress.VisibleChanged
Try
If tspProgress.Visible = True Then
Me.Enabled = False
Startzeit = Now
Dim WorkingStart As
System.Threading.ParameterizedThreadStart = New
System.Threading.ParameterizedThreadStart(AddressO f ShowfrmWorking)
workingThread = New System.Threading.Thread(WorkingStart)
workingThread.SetApartmentState(System.Threading.A partmentState.STA)
workingThread.Start()
Else
Me.Enabled = True
If (Not workingThread Is Nothing AndAlso
workingThread.IsAlive) Then
workingThread.Abort()
End If
While (workingThread.IsAlive)
Application.DoEvents()
End While
End If
Catch ex As Threading.ThreadAbortException
ErrorLog(ex)
Catch ex As Exception
ErrorLog(ex)
End Try
End Sub
--##################################
Public Sub ShowfrmWorking(ByVal Obj As Object)
Try
fWorking = New frmWorking
fWorking.ShowDialog()
Catch ex As Exception
End Try
End Sub
--############################################
Das anzuzeigende Form:
--############################################
Public Class frmWorking
Inherits System.Windows.Forms.Form
Dim Startzeit As DateTime
Private Sub frmWorking_HandleDestroyed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.HandleDestroyed
Try
Timer.Enabled = False
Catch ex As Threading.ThreadAbortException
ErrorLog(ex)
Catch ex As Exception
ErrorLog(ex)
End Try
End Sub
Private Sub frmWorking_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Try
Startzeit = Now
Timer.Enabled = True
Catch ex As Threading.ThreadAbortException
ErrorLog(ex)
Catch ex As Exception
ErrorLog(ex)
End Try
End Sub
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer.Tick
Try
Me.Label1.Text = Format(DateAdd(DateInterval.Second,
DateDiff(DateInterval.Second, Startzeit, Now), New DateTime(Now.Year,
Now.Month, Now.Day, 0, 0, 0)), "00:mm:ss")
Me.Label1.Refresh()
Me.Refresh()
Catch ex As Threading.ThreadAbortException
ErrorLog(ex)
Catch ex As Exception
ErrorLog(ex)
End Try
End Sub
End Class 2 1878
What is the purpose of the below code? Immediately after you start the
thread you are aborting it?
/////////////////
If (Not workingThread Is Nothing AndAlso workingThread.IsAlive) Then
workingThread.Abort()
End If
////////////////
I also think the below is redundant, if you spawn a seperate thread
you shouldn't need to call DoEvents:
//////////////
While (workingThread.IsAlive)
Application.DoEvents()
End While
//////////////
Thanks,
Seth Rowe
Calling Thread.Abort will cause a ThreadAbortException. http://msdn2.microsoft.com/en-us/lib...exception.aspx
Michael W. wrote:
Dear ng,
i have developed a winforms application with vs2005.
An progress from with a animation and a timer is shown while the
application is working.
The trouble is, that often a ThreadAbordException occurs and i can not
identify
whats the reason is.
Can somebody help, please?
Thank you very much
Michael
--##################################################
following code i use:
--##################################
Private Sub tspProgress_VisibleChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tspProgress.VisibleChanged
Try
If tspProgress.Visible = True Then
Me.Enabled = False
Startzeit = Now
Dim WorkingStart As
System.Threading.ParameterizedThreadStart = New
System.Threading.ParameterizedThreadStart(AddressO f ShowfrmWorking)
workingThread = New System.Threading.Thread(WorkingStart)
workingThread.SetApartmentState(System.Threading.A partmentState.STA)
workingThread.Start()
Else
Me.Enabled = True
If (Not workingThread Is Nothing AndAlso
workingThread.IsAlive) Then
workingThread.Abort()
End If
While (workingThread.IsAlive)
Application.DoEvents()
End While
End If
Catch ex As Threading.ThreadAbortException
ErrorLog(ex)
Catch ex As Exception
ErrorLog(ex)
End Try
End Sub
--##################################
Public Sub ShowfrmWorking(ByVal Obj As Object)
Try
fWorking = New frmWorking
fWorking.ShowDialog()
Catch ex As Exception
End Try
End Sub
--############################################
Das anzuzeigende Form:
--############################################
Public Class frmWorking
Inherits System.Windows.Forms.Form
Dim Startzeit As DateTime
Private Sub frmWorking_HandleDestroyed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.HandleDestroyed
Try
Timer.Enabled = False
Catch ex As Threading.ThreadAbortException
ErrorLog(ex)
Catch ex As Exception
ErrorLog(ex)
End Try
End Sub
Private Sub frmWorking_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Try
Startzeit = Now
Timer.Enabled = True
Catch ex As Threading.ThreadAbortException
ErrorLog(ex)
Catch ex As Exception
ErrorLog(ex)
End Try
End Sub
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer.Tick
Try
Me.Label1.Text = Format(DateAdd(DateInterval.Second,
DateDiff(DateInterval.Second, Startzeit, Now), New DateTime(Now.Year,
Now.Month, Now.Day, 0, 0, 0)), "00:mm:ss")
Me.Label1.Refresh()
Me.Refresh()
Catch ex As Threading.ThreadAbortException
ErrorLog(ex)
Catch ex As Exception
ErrorLog(ex)
End Try
End Sub
End Class This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dixp |
last post by:
I'm new to writing multithreaded apps and I have a design question. I
have a winforms app and a class which has a method that does processing
which is time intensive. I want the user to be able...
|
by: Robert Zurer |
last post by:
Can anyone suggest the best book or part of a book on this subject. I'm
looking for an in-depth treatment with examples in C#
TIA
Robert Zurer
robert@zurer.com
|
by: Per Rollvang |
last post by:
Hi All!
I have been struggling with where what & when to set the mousepointer to an
hourglass when using async. multithreading. Nothing seems to work... : (
Anybody that can help me out with...
|
by: BoomWackaBoom |
last post by:
<Newbie disclaimer>
I'm building an ASP.NET/VB port scanner that needs to perform several
"pings" simultaneously on various ports, etc... Obviously, I don't
want this to execute serially, since...
|
by: Keith Henderson |
last post by:
does multithreading work the same way in ASP.NET as it does in winforms? Or
do you have to work with it differently?
Keith O. H.
|
by: Edward W. |
last post by:
Can you do multi-threading in web applications? I basically understand how
to do it in winforms but am not sure about it in web apps. Can someone
point me to to an exmaple or an article that...
|
by: Jefe |
last post by:
Hi everyone,
I used multithreading for a network application using Winsock. so when I
receive a message in my secondary thread, I raise an event to upper layer and
in that event handler when I try...
|
by: sameer |
last post by:
Hi guys, thanks in advance.
trying to implement some multithreading here :
VS 2003
VB.net winforms
I have a dropdown on a form which has list of vendors, when the user selects
a vendor...
|
by: Ray |
last post by:
Hello,
Greetings! I'm looking for a solid C++ multithreading book. Can you
recommend one? I don't think I've seen a multithreading C++ book that
everybody thinks is good (like Effective C++ or...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |