473,508 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending events to main app from a class

I'm writing a class module (to be compiled to .dll). I have a couple of
questions...

1. Is there a way, inside the class, to repeatedly check a value (timer is
not available here), and
2. trigger an event that the main app would catch when the value is true?
Nov 21 '05 #1
7 1061
Hi Terry,

Here is the one way to do that...
Hope it heps
Do reply

Thanks and Regard
Sakharam Phapale
Public Class Class1

Public Event myClassEvent(ByVal Value As Boolean)
Private m_IsVariableTrue As Boolean = False
Private myThread As Threading.Thread

Public Property myVariable() As Boolean
Get
Return m_IsVariableTrue
End Get
Set(ByVal Value As Boolean)
m_IsVariableTrue = Value
End Set
End Property

Public Sub New()
myThread = New Threading.Thread(AddressOf CheckValue)
myThread.Start()
End Sub

Private Sub CheckValue()
While True
If m_IsVariableTrue = True Then
RaiseEvent myClassEvent(m_IsVariableTrue)
End If
End While
End Sub

Protected Overrides Sub Finalize()
myThread.Abort()
MyBase.Finalize()
End Sub

End Class


Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Private WithEvents ObjClass1 As Class1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ObjClass1 = New Class1()
Timer1.Enabled = True
Timer1.Interval = 3000
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub ObjClass1_myClassEvent(ByVal Value As Boolean) Handles
ObjClass1.myClassEvent
MsgBox("Value changed as True")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
ObjClass1 = Nothing
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

If ObjClass1 Is Nothing Then Exit Sub

If ObjClass1.myVariable = True Then
ObjClass1.myVariable = False
Else
ObjClass1.myVariable = True
End If
End Sub

End Class

"Terry Olsen" <to******@hotmail.com> wrote in message
news:O5*************@TK2MSFTNGP11.phx.gbl...
I'm writing a class module (to be compiled to .dll). I have a couple of
questions...

1. Is there a way, inside the class, to repeatedly check a value (timer is
not available here), and
2. trigger an event that the main app would catch when the value is true?

Nov 21 '05 #2
Terry,

1. Is there a way, inside the class, to repeatedly check a value (timer is
not available here), and


This makes me curious, why is there no timer available?

Cor
Nov 21 '05 #3
If a timer is available in this instance, I don't know how to access it.
The only way I know how to access the timer is to drag the timer object onto
a windows form. Since I'm working without a form, no timer...
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eF***************@TK2MSFTNGP11.phx.gbl...
Terry,

1. Is there a way, inside the class, to repeatedly check a value (timer
is not available here), and


This makes me curious, why is there no timer available?

Cor

Nov 21 '05 #4
Going off Sakharam's example (without the timer), you should be able to
throw a Thread.Sleep method in the CheckValue subroutine, so the thread
sleeps for a given time, checks the value, and if it matches, raises the
event which can be handled by whatever main class initiated this one.

-Jason

"Terry Olsen" <to******@hotmail.com> wrote in message
news:eb**************@TK2MSFTNGP09.phx.gbl...
If a timer is available in this instance, I don't know how to access it.
The only way I know how to access the timer is to drag the timer object
onto a windows form. Since I'm working without a form, no timer...
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eF***************@TK2MSFTNGP11.phx.gbl...
Terry,

1. Is there a way, inside the class, to repeatedly check a value (timer
is not available here), and


This makes me curious, why is there no timer available?

Cor


Nov 21 '05 #5
Hi Terry,

I have tried using the WHILE loop, you can also check for the values at
certain interval or frequency by using thread.sleep(); as mentioned in
Jason's email as follows:

"Going off Sakharam's example (without the timer), you should be able to
throw a Thread.Sleep method in the CheckValue subroutine, so the thread
sleeps for a given time, checks the value, and if it matches, raises the
event which can be handled by whatever main class initiated this one."

Try at your end and do let me know.

Thanks and regards,
Sakharam Phapale
"Terry Olsen" <to******@hotmail.com> wrote in message
news:eb**************@TK2MSFTNGP09.phx.gbl...
If a timer is available in this instance, I don't know how to access it.
The only way I know how to access the timer is to drag the timer object onto a windows form. Since I'm working without a form, no timer...
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eF***************@TK2MSFTNGP11.phx.gbl...
Terry,

1. Is there a way, inside the class, to repeatedly check a value (timer
is not available here), and


This makes me curious, why is there no timer available?

Cor


Nov 21 '05 #6
On 2004-11-01, Terry Olsen <to******@hotmail.com> wrote:
I'm writing a class module (to be compiled to .dll). I have a couple of
questions...

1. Is there a way, inside the class, to repeatedly check a value (timer is
not available here), and
2. trigger an event that the main app would catch when the value is true?


There are other timers in the .NET framework... Take a look at
System.Timers.Timer or System.Threading.Timer. Either of these should
handle your needs...

--
Tom Shelton [MVP]
Nov 21 '05 #7
Terry,

When you are used to drag components from the toolbox you can as well use
the component class to create a class.

That goes by opening the solution explorer, rightclick on the solution,
choose for add new and than choose for the component, give it a name and
enter.

Than you can from the toolbox (the component part) the timer from there
about which Tom is talking. You are than busy as with a form.

For the rest I saw some answers, so when you have more questions, please
reply?

Cor
Nov 21 '05 #8

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

Similar topics

2
296
by: Chris | last post by:
Hi, I have an application that contains a class library as another project. The application basically executes DTS packages on a remote SQL Server. This works great. However I want to add...
2
18933
by: Gulshan Oshan | last post by:
I want to implement a simple console that continuously listens for an event from a custom object. I am unable to capture the events from the object. If I subscribe to the events in a windows app...
6
2528
by: Richard | last post by:
Hi, I'm pretty new to C# and only have 6months with vb.net. However my question regards C# and events. Basically I've a class which uses a number of events to inform the main application...
12
2764
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
3
1571
by: Chris | last post by:
Hi, what is the difference between using events and delegates (apart from the syntax) ? have a look at following (working) programs please (you can just copy/paste and build it) : First...
3
2530
by: Chris Dunaway | last post by:
Consider the following simple classes/interfaces defined below. When the derived class raises the events, on which thread is the event code run? Do I need to do anything to catch the events in my...
2
1671
by: MIke Brown | last post by:
Hello all, I've been searching for a solution on google for a problem related to creating events from a worker thread, with no luck.. Basically, the problem is when my events are caught by a...
15
2595
by: Bryce K. Nielsen | last post by:
I have an object that starts a thread to do a "process". One of the steps inside this thread launches 12 other threads via a Delegate.BeginInvoke to process. After these 12 threads are launched,...
3
4264
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
0
7132
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...
0
7401
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...
1
7063
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...
0
7504
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...
0
5640
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,...
1
5059
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...
0
4720
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...
0
3211
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...
0
1568
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 ...

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.