Add timer.tick event handler.

  • Thread starter Thread starter Mr. X.
  • Start date Start date
M

Mr. X.

Hello.
I see on some components that I can do I.e:
addHandler myButton.click, eventHandlerSub

But for Timer (is it on System.Timers ?) I cannot handle the tick event.
How can I by some code handle the tick event of the timer ?

Thanks :)
 
Am 03.04.2010 07:16, schrieb Mr. X.:
Hello.
I see on some components that I can do I.e:
addHandler myButton.click, eventHandlerSub

But for Timer (is it on System.Timers ?) I cannot handle the tick event.
How can I by some code handle the tick event of the timer ?


The System.Windows.Forms.Timer does have a Tick event.
System.Timers.Timer and System.Threading.Timer are something different.
 
Hello.
I see on some components that I can do I.e:
addHandler myButton.click, eventHandlerSub

But for Timer (is it on System.Timers ?) I cannot handle the tick event.
How can I by some code handle the tick event of the timer ?

Thanks :)

Here is an example with System.Timers.Timer:

Sub THandler()
Console.WriteLine("Tick")
End Sub
Sub Main()
Dim t As New System.Timers.Timer
AddHandler t.Elapsed, AddressOf THandler
t.Interval = 250
t.Start()
Console.WriteLine("Waiting...")
Console.ReadKey()
End Sub
 
You know that for a form application a windows.forms.timer gives mostly less
trouble than the system (for windows service and console application) or the
threading timer (as it says for multithreading)
 
Yes, I have thought about that ...
I indeed use the system.windows.forms.timer, and not as I have mentioned
mistakenly System.Timers.timer
(what is the best approach ?)

What I need to do is to create a token string, and for each 20 minutes I
need to re-create a token string.
There are two main functions :
1. Create the token-string.
2. Check if the token-string is a valid one.

There may be a problem when checking the token. This may be a minor problem,
but it may be, because there is a probability that I can check the token
while re-create a new token.

I have thought of such solutions (at first glance) :
1. First scenario, which holds the time (in ticks) in a variable.
A major function, which only by this function I can do (by sending it
parameters) : create the token string, or check the token, with interval of
one second. (It calculate and "knows" a specific time where it should be
re-create the token - only at 20 minutes interval and act as a dispatcher.
2. Do a thread. I don’t know if VB is good language for that, but thread is
something else different then using timers.

In both solutions, I need a protected memory, which cannot be changed
synchrony.
Another problem, which make things more complicated, I should think about :
the scenario of creating the token string, and the scenario of checking it
don't occur at the same main process (there are two different program).

I need also, a function, which cannot run asynchrony more then one process
(it may be a dll, but I don't know if dll may be asynchrony for two
process).

Thanks :)
 
OK.
Solved.

For Token :
I wrote a class : clsTokenMgr, that includes CreateToken & CheckToken
functions.

For the timer :
each time, I use the clsTokenMgr function, I do :

....
TokenMgr = new clsTokenMgr()
....
SynLock TokenMgr
TokenMgr.createToken ...
or
TokenMgr.CheckToken
End SynLock

I see, when I run other exe-file , even I don't call some of TokenMgr
methods in the called exe, When there is a SynLock TokenMgr in the main
calling exe, computer waits, anyway.
Since when there is waiting - I am on a thread (timer), it doesn't bother
(this is the only situation, when there may be an infinitive wait).

Thanks :)
 
Great it is solved but I would suggest to always explain what is the non
technical overall goal. It helps to raise better suggestion including doing
this in other and possibly simplest ways..
 
O.K.

Let's start over.
I am developing Mini-ERP system, but a very smart one. Fits for lot of
industries, with minimal tables and code. Has multilingual support, and a
very modular system.
I made the whole design and tables, programmed some code, and also checked
out the market needs.
If you live on Israel, you see the first burst out of the system.

There is a lot of "but" ... and the most difficult thing to do is obviously
the marketing, and to sell my first product.
Also, that I somehow ask silly question, in order to get good answers, and
this helps me a lot.
Don't get confused for the massive silly question I asked. I have lot of
years experiment, using many technologies, but due some personal issues, for
years - I get stuck ...
I hope my question will be reduced soon. There is a light for the hours I
spend for the system, and many intelligence behind code.

Anyway - Thanks :)
 
I meant more specifically that what you told us is that you needed to check
and recreate a "string token". It seems to be checked every second (?!) and
recreated every 20 minutes but we have no idea about the usage of this
string token.

Knowing what is the purpose of this string token could perhaps allow someone
to give suggestion about achieving the same goal another way. I've seen this
several times (i.e the question is about a particular technical issue but
later when knowing the overall goal one come and says "hey you could do that
this better way instead !").
 
OK.
There is a system (main program - which has a menu).
The main program run (by choosing the menu) another exec program.
When I close the called program, I return to main program.

Each program I called is an exe.
I don't want that the exe program will be run as stand-alone, but only by
the main program.

So, the main program calculates a token string, and send it as a parameter
to the called program.
The called program has this token string, and when first enter the called
program, I check the validity of the token string.
If everything is OK, so I can go on.

There is a choice, that the called program is not closed for hours, and I
don't want that the token string will stayed (when it is calculated, it is
stored on database for the specific user),
so I renew it for about 20 minutes.

For the one second checking - It's not the issue.
I just want a solution, that if I use a timer, there won't be any
thread-problems, so one solution, as far as I know (and not good enough),
is to make one timer, that acts as a dispatcher (all the related commands
are triggered by the timer) - That's the reason for one second,
because checking if token is OK, should return answer immediately, and one
second is negligible for waiting.

Thanks :)
 
Each program I called is an exe.
I don't want that the exe program will be run as stand-alone, but only by
the main program.

So why to built them as EXE files ? By using DLLs you could likely better
tied them to your main application (not sure what is the problem of runnig
them directly if the main app is nothing more than a kind of "menu" which is
for now my understanding)...
So, the main program calculates a token string, and send it as a parameter
to the called program.
The called program has this token string, and when first enter the called
program, I check the validity of the token string.

With a DLL scenario you could perhaps check the identity of the caller
perhaps based on a strong name. Additionaly it allows to check that nothing
was changed i.e. someone tried to decompile/recompile your code even though
I assume your code is obsfucated.
If everything is OK, so I can go on.
There is a choice, that the called program is not closed for hours, and I
don't want that the token string will stayed (when it is calculated, it is
stored on database for the specific user),

Storing it in a db seems a weak point.
For the one second checking - It's not the issue.
I just want a solution, that if I use a timer, there won't be any
thread-problems, so one solution, as far as I know (and not good enough),
is to make one timer, that acts as a dispatcher (all the related commands
are triggered by the timer) - That's the reason for one second,
because checking if token is OK, should return answer immediately, and one
second is negligible for waiting.

Not sure about the overall architecture but my very first thought when
seeing your post is that you could check this sometimes (i.e when a
frequently used function is called and keep the last date/time it was
generated to renew it when enough time elapsed, this way you don't need any
timer).

Unfamiliar with this, but it looks also quite similar to a licensing scheme
(http://msdn.microsoft.com/en-us/library/fe8b1eh9.aspx).
 
O.K.
I will check that out.
Maybe I shall adopt some of your advices (especially use dlls)

Thanks :)
 
Back
Top