473,390 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

DLL, THREAD and I can not stop it

Hi,

I created application that I get information from AS400 for reporting.
In main.exe has only 1 frm which calls (as a class library) CLS_MAIN.dll.
The CLS_MAIN.dll get the tables from AS400 and stores it in Dataset.
Then returns to main frm then main frm calls the FirstReport.dll.
The FirstReport.dll get the information from access database and creates the
sqkl string and works with dataset and then writes in pre-formated Excel
sheet.

I create main_thread in main form(frm) that calls for CLS_MAIN(dll), then
FirstReport(dll) and WriteInEXCELL(dll).

Now while is doing this I createted cancel button. Main purpose of this that
user can be able to cancel creating first report and can goto second report.

But I cannot be able to stoping the thread. When I use serverThread.Abort()
it goes to main form and when user try to create second Report gets exepction
that Thread did not stoped or cannot create same thread again.

I want to cancel the thread then user can send different parameter so she or
he can be able to create different report.

I learn that I should use the serverThread.Join() after the calling the
serverThread.Abort(). But I don't know how to applie to my application.

I also like to know how to unload the class(dll's).

I thank you in advance to helping me out.

Rgds,
Niyazi
Jul 21 '05 #1
3 1704
Niyazi,

Not 100% sure I got your question...
Here are my 2 swiss cents:

When calling thread.abort, this will raise an abortException in the thread.
It is up to you to catch it so as to perform clean up.
If I recall correctly, you cannot reuse your instance of the thread that was
previouly aborted. You have to get a fresh one and call the start method.

- Jos

"Niyazi" <Ni****@discussions.microsoft.com> a crit dans le message de news:
B1**********************************@microsoft.com...
Hi,

I created application that I get information from AS400 for reporting.
In main.exe has only 1 frm which calls (as a class library) CLS_MAIN.dll.
The CLS_MAIN.dll get the tables from AS400 and stores it in Dataset.
Then returns to main frm then main frm calls the FirstReport.dll.
The FirstReport.dll get the information from access database and creates
the
sqkl string and works with dataset and then writes in pre-formated Excel
sheet.

I create main_thread in main form(frm) that calls for CLS_MAIN(dll), then
FirstReport(dll) and WriteInEXCELL(dll).

Now while is doing this I createted cancel button. Main purpose of this
that
user can be able to cancel creating first report and can goto second
report.

But I cannot be able to stoping the thread. When I use
serverThread.Abort()
it goes to main form and when user try to create second Report gets
exepction
that Thread did not stoped or cannot create same thread again.

I want to cancel the thread then user can send different parameter so she
or
he can be able to create different report.

I learn that I should use the serverThread.Join() after the calling the
serverThread.Abort(). But I don't know how to applie to my application.

I also like to know how to unload the class(dll's).

I thank you in advance to helping me out.

Rgds,
Niyazi

Jul 21 '05 #2
Hi Jose,
Thank you for info.
When I catch the exeption then what should I do, without killing main.exe?
The thread reside in main.exe. Also how to create fresh thread?

In frmMain I use this code:
'PRIVATE MEMBERS
'Server Thread
Private serverThread As New Thread(AddressOf _MAIN_THREAD)

When user clicks the button does some userinterface changes and then call the
Private Sub playAnime() that shows Macromedia Flash loading, creating anime
and then calls the tread as:

If Panel1.Visible = True Then
serverThread.Start()
End If

and then in _MAIN_THREAD I have this:

'MAIN THREAD
Sub _MAIN_THREAD()
'FOR TBAccess.mdb
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++
Try
'FOR DATASET
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
‘clsConst, clsDSFill in the clsMAIN class library

If clsConst.m_DSLoaded = False Then
Try
'Call DATASET fill class
Dim callDS As New clsDSFill("I am calling")
Catch ex As Exception
MsgBox("ex.Message.ToString)
End Try
Else
'Load the data from AS400 from first report,
'When user try to run second report onward application
'will use the loaded data from Data set
End If


'ALL CLASSES HAS TO BE CALLED IN HERE
++++++++++++++++++++++++++++++++++++++++++
‘[clsBL100A_TableName -> clsReadAccNo -> clsDataFromAS400]

Try
'READ ACCOUNT NO from MS ACCESS DB to GET Information (SUM) from
AS400
Dim tableSize As Integer
If clsConst.checkedBox = "BL100A" Then
For tableSize = 1 To 46
'Call CLASS LOOP [ clsBL100A_TableName -> clsReadAccNo ->
clsDataFromAS400 ]
Dim _CALL_TABLE_NAME As New
BL100A.clsBL100A_TableName(CStr(tableSize))
Next
ElseIf clsConst.checkedBox = "KZ100A" Then
For tableSize = 1 To 33
'Call CLASS LOOP [ clsKZ100A_TableName -> clsReadAccNo ->
clsDataFromAS400 ]
Dim _CALL_TABLE_NAME As New
KZ100A.clsKZ100A_TableName(CStr(tableSize))
Next
ElseIf ……………….
‘………………………
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
‘+++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++

'WRITING/CREATING (IN) NEW EXCEL SHEET
++++++++++++++++++++++++++++++++++++++++
Try
If clsConst.checkedBox = "BL100A" Then
'Create EXCEL REPORT for BL100A
Dim KEMAL As New BL100A.clsWINEXCEL
ElseIf clsConst.checkedBox = "KZ100A" Then
'Create EXCEL REPORT for KZ100A
Dim KEMAL As New KZ100A.clsWINEXCEL
Else
MsgBox("clsConst.checkedBox does not contain valid data",
MsgBoxStyle.Information)
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
Thread creates a report maximum 7 min and min 1.30 min.
But if user clicks cancel button I need to kill the thread but not the
main.exe
So user can get different report.

Here is the Cancel button code:

Try
'Stop the SERVER_THREAD
serverThread.Abort()
If clsConst.checkedBox = "BL100A" Then
chkBL100A.Enabled = True
'Show the check mark graphic
pBox1.Visible = False
AxShockwaveFlash1.Stop()
Panel1.Visible = False
ElseIf clsConst.checkedBox = "KZ100A" Then
chkKZ100A.Enabled = True
'Show the check mark graphic
pBox2.Visible = False
AxShockwaveFlash1.Stop()
Panel1.Visible = False
End if

btnENTER.Enabled = True

Catch ex As Exception
MsgBox(ex.Message)
Finally
serverThread.Join()
End Try
As you can see I create the New instance of the Main thread but after I
cancel and try to get other report I get an error. I know when I abort the
thread I have to wait a certain time to thread will be realy dead. So I
should warn the user while the threat aborting that "Wait! Canceling the
......Report".

But having hard time to to code this. Also if I catch the exception How to
perform the clean up.

I realy appriciate your info, and I hope you can help me bit more.

Rgds,
Niyazi
Jul 21 '05 #3
Hi Jose,
Thank you for info.
When I catch the exeption then what should I do, without killing main.exe?
The thread reside in main.exe. Also how to create fresh thread?

In frmMain I use this code:
'PRIVATE MEMBERS
'Server Thread
Private serverThread As New Thread(AddressOf _MAIN_THREAD)

When user clicks the button does some userinterface changes and then call the
Private Sub playAnime() that shows Macromedia Flash loading, creating anime
and then calls the tread as:

If Panel1.Visible = True Then
serverThread.Start()
End If

and then in _MAIN_THREAD I have this:

'MAIN THREAD
Sub _MAIN_THREAD()
'FOR TBAccess.mdb
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++
Try
'FOR DATASET
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
‘clsConst, clsDSFill in the clsMAIN class library

If clsConst.m_DSLoaded = False Then
Try
'Call DATASET fill class
Dim callDS As New clsDSFill("I am calling")
Catch ex As Exception
MsgBox("ex.Message.ToString)
End Try
Else
'Load the data from AS400 from first report,
'When user try to run second report onward application
'will use the loaded data from Data set
End If


'ALL CLASSES HAS TO BE CALLED IN HERE
++++++++++++++++++++++++++++++++++++++++++
‘[clsBL100A_TableName -> clsReadAccNo -> clsDataFromAS400]

Try
'READ ACCOUNT NO from MS ACCESS DB to GET Information (SUM) from
AS400
Dim tableSize As Integer
If clsConst.checkedBox = "BL100A" Then
For tableSize = 1 To 46
'Call CLASS LOOP [ clsBL100A_TableName -> clsReadAccNo ->
clsDataFromAS400 ]
Dim _CALL_TABLE_NAME As New
BL100A.clsBL100A_TableName(CStr(tableSize))
Next
ElseIf clsConst.checkedBox = "KZ100A" Then
For tableSize = 1 To 33
'Call CLASS LOOP [ clsKZ100A_TableName -> clsReadAccNo ->
clsDataFromAS400 ]
Dim _CALL_TABLE_NAME As New
KZ100A.clsKZ100A_TableName(CStr(tableSize))
Next
ElseIf ……………….
‘………………………
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
‘+++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++

'WRITING/CREATING (IN) NEW EXCEL SHEET
++++++++++++++++++++++++++++++++++++++++
Try
If clsConst.checkedBox = "BL100A" Then
'Create EXCEL REPORT for BL100A
Dim KEMAL As New BL100A.clsWINEXCEL
ElseIf clsConst.checkedBox = "KZ100A" Then
'Create EXCEL REPORT for KZ100A
Dim KEMAL As New KZ100A.clsWINEXCEL
Else
MsgBox("clsConst.checkedBox does not contain valid data",
MsgBoxStyle.Information)
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
Thread creates a report maximum 7 min and min 1.30 min.
But if user clicks cancel button I need to kill the thread but not the
main.exe
So user can get different report.

Here is the Cancel button code:

Try
'Stop the SERVER_THREAD
serverThread.Abort()
If clsConst.checkedBox = "BL100A" Then
chkBL100A.Enabled = True
'Show the check mark graphic
pBox1.Visible = False
AxShockwaveFlash1.Stop()
Panel1.Visible = False
ElseIf clsConst.checkedBox = "KZ100A" Then
chkKZ100A.Enabled = True
'Show the check mark graphic
pBox2.Visible = False
AxShockwaveFlash1.Stop()
Panel1.Visible = False
End if

btnENTER.Enabled = True

Catch ex As Exception
MsgBox(ex.Message)
Finally
serverThread.Join()
End Try
As you can see I create the New instance of the Main thread but after I
cancel and try to get other report I get an error. I know when I abort the
thread I have to wait a certain time to thread will be realy dead. So I
should warn the user while the threat aborting that "Wait! Canceling the
......Report".

But having hard time to to code this. Also if I catch the exception How to
perform the clean up.

I realy appriciate your info, and I hope you can help me bit more.

Rgds,
Niyazi
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olivier Parisy | last post by:
Hi, I like to use thread to simplify the handling of independant, blocking tasks. But controling them from a main thread is not always easy to do in a clean way. So I've written some generic...
9
by: Harald Armin Massa | last post by:
I need to do some synchronisations like in a cron.job import time from threading import Thread class updater(Thread): def run(self): while True: do_updates() time.sleep(600)
6
by: Tomaz Koritnik | last post by:
I have a class that runs one of it's method in another thread. I use Thread object to do this and inside ThreadMethod I have an infinite loop: While (true) { // do something Thread.Sleep(100);...
4
by: fred | last post by:
I use a Synclock in a secondary thread and also stop the thread using the abort method. If the abort occurs while the thread is in the Synclock will the SyncLock always be released before the...
6
by: Joe Jax | last post by:
I have an object that spawns a worker thread to process one of its methods. That method processes methods on a collection of other objects. During this processing, a user may request to cancel the...
5
by: Soren S. Jorgensen | last post by:
Hi, In my app I've got a worker thread (background) doing some calculations based upon user input. A new worker thread might be invoked before the previous worker thread has ended, and I wan't...
5
by: Alan T | last post by:
I will do several things in my thread: Copy a file to a location Update database record Read the file content Write the content to a log file If I call Thread.Abort(), it may be possible to...
10
by: Jon Slaughter | last post by:
Since a thread doesn't have a Stop feature and I'm not supose to use abort, I'm wondering how I stop a thread? My problem is that I simply want to excute a function in the background and...
3
by: yeye.yang | last post by:
hey everybody Does everybody can help me or give me some advise for the cross thread exception catch Here is what I want to do: I have 2 classes "Scenario" and "Step", which have a...
1
by: raghudr | last post by:
Hi all, I am displaying a splash screen for which i have created a thread.Since my whole project is launched by windows service and that service will start automatically at the start of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
1
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.