473,385 Members | 1,642 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,385 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 1703
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...
1
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.