非静态字段需要对象引用. [英] An object reference is required for the non-static field...

查看:169
本文介绍了非静态字段需要对象引用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在此函数中调用存储过程

称为Jobs.cs的类

how to call stored procedure in this function

a class called Jobs.cs

namespace myScheduler
  {
      public sealed class Jobs
      {
          public Jobs(){}

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



我想在(DailyJob)函数中调用过程,而这是我在调用过程DailyJob时出现的错误:

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

删除静态词时出现另一个错误:

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



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)''

TimerCallback callbackDaily = new TimerCallback(Jobs.DailyJob);

推荐答案

MSDN页面上有一个很好的例子 [TimerCallback <的href ="http://msdn.microsoft.com/en-us/library/system.threading.timercallback.aspx" target ="_ blank" title ="New Window"> ^ ]

在该示例中,Callback方法不是静态的,并且在调用它之前创建了该类的实例:
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:
Jobs myJobs = new Jobs();
TimerCallback callbackDaily = new TimerCallback(myJobs.DailyJob);



那就是没有 static访问修饰符.



That is without the static access modifier.


这篇关于非静态字段需要对象引用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆