如何在循环结束时摆脱变量 [英] how to get rid of variable at the end of cycle

查看:100
本文介绍了如何在循环结束时摆脱变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我开发了一个记录器,用于从外部设备收集数据。它应该每秒记录一些数据(int x6,string x4)并且应该24x7运行。在最初的24小时内一切都很好,但随后它就会挂掉,我唯一可以做的就是重新启动整个系统。



有什么方法可以摆脱它每个周期结束时的变量?



谢谢

Hi,

I developed a logger for data gathering from external device. it should record some data (int x6, string x4) once per second and supposed to run 24x7. for the first 24 hours everything is fine but then it hang over and the only thing that i can do is to restart whole system.

is there any method to get rid of variables at the end of each cycle?

Thanks

推荐答案



首先你不应该声明int x6,string x4单独的变量而应该创建一个包含所有必需属性作为属性的类,然后在逻辑代码段内创建类的对象

如果您使用c#代码,最好的方法是将您的逻辑代码放在Using子句中。其次,您可以在类中返回逻辑的Idisposable接口实现

下面给出的示例

您将变量作为类



Hi,
First of all you should not declare int x6, string x4 separate variables instead you should create a class including all the required attributes as properties and then create the object of the class inside logical piece of code
if you are using c# code behind the best way is to put your logical piece of code inside Using clause. secondly you can implement the Idisposable interface in the class where you have return the logic
example given below
you variables as class

public class clsEmail
   {
       public string EmailFrom
       {
           get { return _EmailFrom; }
           set { _EmailFrom = value; }
       }
       public string EmailTo
       {
           get { return _emailTo; }
           set { _emailTo = value; }
       }
       public string Emailcc
       {
           get { return _emailcc; }
           set { _emailcc = value; }
       }
       public string EmailSub
       {
           get { return _EmailSub; }
           set { _EmailSub = value; }
       }
       public string Emailbody
       {
           get { return _Emailbody; }
           set { _Emailbody = value; }
       }



}




}

using (someEntities objDataContext = new someEntities())
                {
clsEmail obj=new clsEmail();
class1 objclass=new Class1
                    inboxId = (from inbox in objTWEYPSDataContext.tblInboxItems
                               where inbox.RequestId == RequestId && inbox.StartedBy == startedBy && inbox.State == actionState
                               select inbox.InboxId).SingleOrDefault();

                    return inboxId;
                }







一旦你从上面的逻辑代码中拿出所有对象,比如objDataContext ,objclass和obj / pre>等将被销毁






Once you come out of the above logical code all the objects like objDataContext, objclass and obj/pre> etc will be destroyed




谢谢和问候

Murtuza


Thanks and regards
Murtuza


这篇关于如何在循环结束时摆脱变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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