Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
how to call stored procedure in this function

a class called Jobs.cs
C#
namespace myScheduler
  {
      public sealed class Jobs
      {
          public Jobs(){}

          public static void DailyJob(object state)
          {
             //Your dream goes here.
          }
               ...
           }
           ...
        }


I want to call procedure in (DailyJob) function and this is the error when I call procedure DailyJOb:

An object reference is required for the non-static field, method, or property 'myScheduler.Jobs.con

when remove static word another error :

An object reference is required for the non-static field, method, or property 'myScheduler.Jobs.DailyJob(object)'

C#
TimerCallback callbackDaily = new TimerCallback(Jobs.DailyJob);
Posted
Updated 1-Apr-11 4:32am
v2

1 solution

There is a good example on the MSDN page[^] for TimerCallback

In that example the Callback method is not static and an instance of it's class is created prior to calling it:
C#
Jobs myJobs = new Jobs();
TimerCallback callbackDaily = new TimerCallback(myJobs.DailyJob);


That is without the static access modifier.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Apr-11 12:13pm    
My 5. OP needs to learn about objects, classes, instances, everything... not just static or not static.
--SA
Henry Minute 1-Apr-11 12:14pm    
True!

That's why I gave code rather than just try to explain.
Sergey Alexandrovich Kryukov 1-Apr-11 12:33pm    
I can understand you.

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