Better than Timer t...
 
Notifications
Clear all

Better than Timer tutorial!

Page 1 / 4

Cain532
Posts: 1280
Topic starter
(@cain532)
Noble Member
Joined: 10 years ago

So, today we are going to be learning how to do away with slow, clunky, laggy timers and ramp things up with minimal to no impact to your project!!!

For those of you who don't know what timers are and how they are used, typically speaking you would use them to write a process or function constantly, or to monitor various things such as int's and so on.

One thing to use timers for is monitoring bytes via

int Check;

Check = PS3.Extension.ReadInt32(PS3.Extension.ReadByte(0x84934523));

This will display the information at 0x84934523, we can use a timer to constantly read this.

There are loads of other things you can do with timers, but I won't be getting into that here.

On with the tutorial!!!

Biggest difference between Timers and Background Workers is that Background Workers are essentially ALWAYS running (unless you programmicatically end them)
Timers can be either way, but the longer you have a timer running, the more chance of lag you have.

So, first and foremost, you are going to want to get a background worker added to your project, you can find it in your Toolbox.

Once you have added that, name it whatever you want. for this demonstration we will be naming it "worker".

Double click worker to go into your coding window; here is where we will start the magic!

We need to declare an bool somewhere outside of the background worker, you can do that almost anywhere simply type something like "bool i;" without quotations.

Then inside the bgworker, we will be referencing that bool like this;

while (i) //The function will run so long as Bool i returns a "true" value
{
Invoke(new MethodInvoker(delegate()
{
//Put your code here!!!
})); // Invoke allows the background worker to interact with objects within your Form.
}

We use a Bool because it can be toggled on or off. It's the same thing as using timer1.Start(); or timer1.Stop();

Now, make yourself either a button or a checkbox, we will be using a button for this example

Once you get your button placed, double click it and put this in there;

i = !i; //this toggles the bool each time the button is pressed
if (!worker.IsBusy) //this checks if the worker is already on or not.
worker.RunWorkerAsync();

That's it!! Enjoy your ridiculously fast functioning!

Here is a bit of a comparison for you all just to put things in perspective 🙂

Reply
17 Replies
Cyb3r
Posts: 1598
(@cyb3r)
Noble Member
Joined: 10 years ago

This is really helpful, this could get handy later with my next tool thanks for sharing Brandon!

Reply
KranK
Posts: 336
(@KranK)
Reputable Member
Joined: 10 years ago

huh im remember that 😛

Reply
Beadsman20
Posts: 67
(@Beadsman20)
Trusted Member
Joined: 10 years ago

Good job cain will definitely come in handy

Reply
Rage
Posts: 164
 Rage
(@Rage)
Estimable Member
Joined: 9 years ago

So, today we are going to be learning how to do away with slow, clunky, laggy timers and ramp things up with minimal to no impact to your project!!!

For those of you who don't know what timers are and how they are used, typically speaking you would use them to write a process or function constantly, or to monitor various things such as int's and so on.

One thing to use timers for is monitoring bytes via

int Check;

Check = PS3.Extension.ReadInt32(PS3.Extension.ReadByte(0x84934523));

This will display the information at 0x84934523, we can use a timer to constantly read this.

There are loads of other things you can do with timers, but I won't be getting into that here.

On with the tutorial!!!

Biggest difference between Timers and Background Workers is that Background Workers are essentially ALWAYS running (unless you programmicatically end them)
Timers can be either way, but the longer you have a timer running, the more chance of lag you have.

So, first and foremost, you are going to want to get a background worker added to your project, you can find it in your Toolbox.

Once you have added that, name it whatever you want. for this demonstration we will be naming it "worker".

Double click worker to go into your coding window; here is where we will start the magic!

We need to declare an bool somewhere outside of the background worker, you can do that almost anywhere simply type something like "bool i;" without quotations.

Then inside the bgworker, we will be referencing that bool like this;

while (i) //The function will run so long as Bool i returns a "true" value
{
Invoke(new MethodInvoker(delegate()
{
//Put your code here!!!
})); // Invoke allows the background worker to interact with objects within your Form.
}

We use a Bool because it can be toggled on or off. It's the same thing as using timer1.Start(); or timer1.Stop();

Now, make yourself either a button or a checkbox, we will be using a button for this example

Once you get your button placed, double click it and put this in there;

i = !i; //this toggles the bool each time the button is pressed
if (!worker.IsBusy) //this checks if the worker is already on or not.
worker.RunWorkerAsync();

That's it!! Enjoy your ridiculously fast functioning!

Here is a bit of a comparison for you all just to put things in perspective 🙂

Nice, the way I program my tools they tend to never lag but I have many timers and if doing this helps then great, now my tools can be faster !!

Another thing that causes lag is webBrowsers but I don't think there is a way to stop that from making the tool slow down other than to try to keep everything going in one webBrowser lol

Going to use this to code something that is going to help every programmer trying to make money off there tools without charging the users earn extra, as long as the tool is open the programmer will be making money 😀

Reply
Page 1 / 4