473,800 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Terminating code called from a delegate

Hello all

Within my reports form i have used delegates to allow a crystall
reports to generate without holding up the user.

The user selects a report from tree view, enters the appropriate data
and then hits the "Display" button. At this point the delegate is
created and fired via BeginInvoke.

The code run within the delegate call includes calls to the database
to retrieve data, insertion of data into a dataset, as well as some
business logic. Eventually the ReportSource is set to the crystall
report and displayed in the CrystalReportVi ewer.

I currently know that i have some no nos within my code as i am
accessing Control objects outside of the main UI thread.
(eg. Setting reportViewer.Re portSource = myReport;)
And i will get onto changing this soon.

My problem is:

When the user closes the form the new thread that has been generated
using
myReportDelegat e.BeginInvoke() is still running. I need this code
path to terminate execution. Because when i load the form again the
and go to run another report the DB will still have an open connection
from the thread before.

I have searched google & microsoft and basically i found the example:
HOWTO: Stop Multiple Threads
http://msdn.microsoft.com/library/de...tml/stopmt.asp

This sets a property in the closing event and simply checks this value
in the thread, returning out of the method once the property has been
set to true.

This example is no good in my case as there is no consistent looping
in the thread code so this property cannot be checked regulary

Unless i put
if (HasClosed)
return;

in every 2nd line of code which is very very messy.

Does anyone have an idea of how i can terminate the thread generated
off the delegate when the form closes, or am i completely on the wrong
path with the whole code execution via delegates??

Thanks in advance..

Ginno...
Nov 16 '05 #1
0 1065

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

Similar topics

18
2041
by: Elder Hyde | last post by:
Hey all, A class of mine needs to tell the outside world when its buffer is not empty. The problem is that C# seems to force you to put the event-raising code in the base class. To illustrate, consider what I'll do in Java: public interface DataAvailabilityListener extends java.util.EventListener { void dataArrived(DataAvailabilityEvent event); }
6
9176
by: news.microsoft.com | last post by:
I have a very multi-threaded Windows Forms application. There are many BeginInvoke calls, as well as Thread/ThreadStarts. My issue is that when I quit my application there are often threads hanging around that prevent the process from dying. I've gone through my code line by line looking for orphaned threads, but I'm unable to figure out where they are being created. Is there any way to kill all threads spawned by a process without...
6
23745
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
10
3281
by: Jon | last post by:
I'm investiging multi-threaded GUI applications; specifically the technique used to ensure that controls are only modified under the correct thread. The standard technique is to use if(InvokeRequired == true) ... BeginInvoke(...) ... I have some code that ensures that an event fired from a worker (non-GUI) thread will use the appropriate BeginInvoke call for synchronisation. By offloading the synchronisation onto the worker thread the...
1
1781
by: NvrBst | last post by:
I have a thread pool. Is there a function I can override that all the ThreadPool work queues call before they terminate? IE so I can just do something like override void _threadpoolterminate(...) { //My 1 line of code "Running = false;" base(...); } Kinda thing...
1
7973
by: natarajchakraborty | last post by:
Hi All, I have a serious problem here which is bugging me for past few days. I have a native DLL(Win32), and it exposes only on function called GetFunctionList Now this function takes a pointer to pointer of a Structure as an argument.
15
8212
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a Delegate. My testing showed that actually it was six times faster: 0.5 seconds for 100,000 iterations versus 3.1 seconds. Can anyone explain why? Something in the way I coded it? I'd appreciate any insights. Here's the code (in a Windows Form...
3
1554
by: ropo | last post by:
I have a managed wrapper class that has a delegate to be called from unmanaged code: public ref class CmmMessageCallbackWrapper { private: delegate void InternalMessageDelegate( void*, CmmService::Message::CMessage* ); public: CmmMessageCallbackWrapper()
14
3797
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain more why C++/CLI would be better to PInvoke than doing the PInvoke in C#? Because, usually in C# as you already know we use DLLImport and extern
0
9690
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
10275
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...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7576
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...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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.