473,624 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(d ll).

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.Ab ort()
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.Jo in() after the calling the
serverThread.Ab ort(). 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 1716
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****@discuss ions.microsoft. com> a écrit dans le message de news:
B1************* *************** **...icrosof t.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(d ll).

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.Ab ort()
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.Jo in() after the calling the
serverThread.Ab ort(). 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(AddressO f _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.St art()
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_DSLo aded = False Then
Try
'Call DATASET fill class
Dim callDS As New clsDSFill("I am calling")
Catch ex As Exception
MsgBox("ex.Mess age.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_Table Name -> clsReadAccNo -> clsDataFromAS40 0]

Try
'READ ACCOUNT NO from MS ACCESS DB to GET Information (SUM) from
AS400
Dim tableSize As Integer
If clsConst.checke dBox = "BL100A" Then
For tableSize = 1 To 46
'Call CLASS LOOP [ clsBL100A_Table Name -> clsReadAccNo ->
clsDataFromAS40 0 ]
Dim _CALL_TABLE_NAM E As New
BL100A.clsBL100 A_TableName(CSt r(tableSize))
Next
ElseIf clsConst.checke dBox = "KZ100A" Then
For tableSize = 1 To 33
'Call CLASS LOOP [ clsKZ100A_Table Name -> clsReadAccNo ->
clsDataFromAS40 0 ]
Dim _CALL_TABLE_NAM E As New
KZ100A.clsKZ100 A_TableName(CSt r(tableSize))
Next
ElseIf …………… ….
‘………… ……………
End If
Catch ex As Exception
MsgBox(ex.Messa ge.ToString)
End Try
‘++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++

'WRITING/CREATING (IN) NEW EXCEL SHEET
+++++++++++++++ +++++++++++++++ ++++++++++
Try
If clsConst.checke dBox = "BL100A" Then
'Create EXCEL REPORT for BL100A
Dim KEMAL As New BL100A.clsWINEX CEL
ElseIf clsConst.checke dBox = "KZ100A" Then
'Create EXCEL REPORT for KZ100A
Dim KEMAL As New KZ100A.clsWINEX CEL
Else
MsgBox("clsCons t.checkedBox does not contain valid data",
MsgBoxStyle.Inf ormation)
End If
Catch ex As Exception
MsgBox(ex.Messa ge.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.Ab ort()
If clsConst.checke dBox = "BL100A" Then
chkBL100A.Enabl ed = True
'Show the check mark graphic
pBox1.Visible = False
AxShockwaveFlas h1.Stop()
Panel1.Visible = False
ElseIf clsConst.checke dBox = "KZ100A" Then
chkKZ100A.Enabl ed = True
'Show the check mark graphic
pBox2.Visible = False
AxShockwaveFlas h1.Stop()
Panel1.Visible = False
End if

btnENTER.Enable d = True

Catch ex As Exception
MsgBox(ex.Messa ge)
Finally
serverThread.Jo in()
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(AddressO f _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.St art()
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_DSLo aded = False Then
Try
'Call DATASET fill class
Dim callDS As New clsDSFill("I am calling")
Catch ex As Exception
MsgBox("ex.Mess age.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_Table Name -> clsReadAccNo -> clsDataFromAS40 0]

Try
'READ ACCOUNT NO from MS ACCESS DB to GET Information (SUM) from
AS400
Dim tableSize As Integer
If clsConst.checke dBox = "BL100A" Then
For tableSize = 1 To 46
'Call CLASS LOOP [ clsBL100A_Table Name -> clsReadAccNo ->
clsDataFromAS40 0 ]
Dim _CALL_TABLE_NAM E As New
BL100A.clsBL100 A_TableName(CSt r(tableSize))
Next
ElseIf clsConst.checke dBox = "KZ100A" Then
For tableSize = 1 To 33
'Call CLASS LOOP [ clsKZ100A_Table Name -> clsReadAccNo ->
clsDataFromAS40 0 ]
Dim _CALL_TABLE_NAM E As New
KZ100A.clsKZ100 A_TableName(CSt r(tableSize))
Next
ElseIf …………… ….
‘………… ……………
End If
Catch ex As Exception
MsgBox(ex.Messa ge.ToString)
End Try
‘++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++

'WRITING/CREATING (IN) NEW EXCEL SHEET
+++++++++++++++ +++++++++++++++ ++++++++++
Try
If clsConst.checke dBox = "BL100A" Then
'Create EXCEL REPORT for BL100A
Dim KEMAL As New BL100A.clsWINEX CEL
ElseIf clsConst.checke dBox = "KZ100A" Then
'Create EXCEL REPORT for KZ100A
Dim KEMAL As New KZ100A.clsWINEX CEL
Else
MsgBox("clsCons t.checkedBox does not contain valid data",
MsgBoxStyle.Inf ormation)
End If
Catch ex As Exception
MsgBox(ex.Messa ge.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.Ab ort()
If clsConst.checke dBox = "BL100A" Then
chkBL100A.Enabl ed = True
'Show the check mark graphic
pBox1.Visible = False
AxShockwaveFlas h1.Stop()
Panel1.Visible = False
ElseIf clsConst.checke dBox = "KZ100A" Then
chkKZ100A.Enabl ed = True
'Show the check mark graphic
pBox2.Visible = False
AxShockwaveFlas h1.Stop()
Panel1.Visible = False
End if

btnENTER.Enable d = True

Catch ex As Exception
MsgBox(ex.Messa ge)
Finally
serverThread.Jo in()
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
2402
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 code whose purpose is to start and stop threads in a synchronous (blocking) way from the caller's point of view. Hence, after start() is called you are garanteed that the thread is running, and after stop() you know it has completed
9
2407
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
23727
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); } The problem is that I don't know how to terminate the thread when my class
4
2546
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 thread stops or do I need to add some extra code to avoid Synclock staying on after the thread has been stopped. Thanks Fred
6
5983
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 entire operation. I could request abort on the worker thread, but that is a) potentially messy, and b) not guaranteed to take immediate effect anyway. I would rather have some way of allowing the main thread to tell the worker thread that it...
5
3536
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 only one worker thread running at any time (if a new worker thread start has been requested, any running worker thread results will be invalid). I'm using the below method to invoke a new worker thread, but when stress testing this I'm sometimes...
5
2791
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 stop at the middle of the something ?
10
2187
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 possibly "restart" it. What've been doing is essentially: if (SerialRowThread != null)
3
3176
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 System.Thread.Timer for each to control their timeout gestion, in my "main program", I start the "Scenario" and "Step", and I do something between "StepStart" and "StepStop", when "Scenario" or "Step" timeout expired, they raise an "exception", then my "main...
1
2520
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 PC and sometimes when i start or restart the PC i have observed that even though the long process is completed splash
0
8246
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8631
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.