Link to home
Start Free TrialLog in
Avatar of Tech_Men
Tech_MenFlag for Israel

asked on

function that i need to run every 1 min in win form app

hi there ,
i need to make a call to db every 1 min
i try to do this :
 private static void GetLids()
	    {
            var timer = new System.Threading.Timer(
              s => GetLidsFromSsd(),
              null,
              TimeSpan.Zero,
              TimeSpan.FromMinutes(1));

	        MessageBox.Show(DateTime.Now.ToString());


	    }
	    private static void GetLidsFromSsd()
	    {
            EfLids.GetLidsFromApi();
	    }

Open in new window

i call this func in FormLoad but its run only 1 time when the app first open
how can i fix this that its will work every min
whit out frees my app

thanks ...
Avatar of HainKurt
HainKurt
Flag of Canada image

set AutoReset to true and try again
or define timer as a public var and call timer.start after db call

var timer  System.Threading.Timer;
private static void GetLids()
	    {
              timer = new System.Threading.Timer(
              s => GetLidsFromSsd(),
              null,
              TimeSpan.Zero,
              TimeSpan.FromMinutes(1));
	    }

	    private static void GetLidsFromSsd()
	    {
            EfLids.GetLidsFromApi();
            timer.start();
	    }

Open in new window

Avatar of Tech_Men

ASKER

var timer  System.Threading.Timer; its not legal in c# and i don't see the option start in timer
please answer only if you know ...
thanks
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
very nice thanks...
var timer  System.Threading.Timer; its not legal in c# and i don't see the option start in timer
please answer only if you know ...

that was your code!!!...

if you dont know how to to write code, then first learn how to write code before asking...