Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Having a bit of trouble contemplating this rule here. What does the rule '+=' do in:

C#
private void button_Click(object sender, EventArgs e)
{
    Foo.Tick += Foo_Tick;
    Foo.Start();
}

void Foo_Tick(object sender, NewFrameEventArgs eventArgs)
{
    // Do sh*t...
}


thats different than just adding a timer to your form and starting it:

C#
private void button_Click(object sender, EventArgs e)
{
    timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
    // Do sh*t...
}


What I have tried:

I want to be able to update a sequence of bitmap images to shows on screenm but I feel like a timer isn't enough to shows these images on time. Is a timer reliable enough to show motion at a high framerate from a sequence of images?

My code is not the issue, I just don't see what the difference is between the two functions.
Posted
Updated 5-Sep-21 14:50pm
v3

It's not "+" and "=" as a "rule", it's the "+=" operator, which does a similaar thing to what it does for an integer:
C#
int x = 666;
x += 334;
Console.WriteLine(x);
Here it adds 334 to the existing value of 666 and prints the result: 1000
With an event handler, it does a similar thing: adds a handler to the event handler chain so that it gets called when the event is fired.

And no, a timer isn't "accurate" - it will happen "at some point" after the timeout period has elapsed, but your handler method isn't guaranteed to be called immediately the Tick happens. Windows isn't a real-time operating system which is the only time that timed events can be guaranteed to occur at a particular frequency.

I'd convert the images to a stream or video, and play that instead.
 
Share this answer
 
Comments
CPallini 2-Sep-21 2:02am    
5.
Maciej Los 2-Sep-21 4:06am    
Well explained!
An Event is a special type of delegate (EventHandler) container; it is multi-cast, meaning that it maintains an "invocation list," an internal list of "subscribers" that it will "notify" any time it is executed (invoked).

I consider this is not equivalent to "assignment" of a value to a variable.

Think of the difference between;

"My phone number is #####"

and

"Please add my phone number, #####, to the list of people you call when Microsoft stock price drops more than US$ 20"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900