当前位置:编程学习 > C#/ASP.NET >>

还有个问题!!!为什么我在上面明明定义了count,counttrue,stop...等等,在 static public void IOCPThreadFunction(int iValue)却用不了,要求从新

using   System; 
using   System.Collections.Generic; 
using   System.ComponentModel; 
using   System.Drawing; 
using   System.Data; 
using   System.Text; 
using   System.Windows.Forms; 
using   System.Threading; 
using   System.IO.Ports; 

namespace   rating 

        public   partial   class   DistancePulse   :   UserControl 
        { 
            double   i   =   0; 
            string   direction   =   "1"; 
              double   stopechain   =   0; 
            Boolean     count=true; 
                Boolean   counttrue   =   false; 
            int   stop   =   1; 
            Thread   pulsesThread; 
              public   SerialPort   port   =   new   SerialPort("COM4",   9600,   Parity.None,   8,   StopBits.One); 
            
                public   DistancePulse() 
                { 
                        InitializeComponent(); 
              
                } 
                private   void   btn_play_Click(object   sender,   EventArgs   e) 
                { 
                        try 
                        { 

                                port.Open(); 
                        } 
                        catch   (Exception   ex)   {   }         
                        stop   =   1; 

    

                        //   Create   the   MSSQL   IOCP   Thread   Pool   
                        IOCPThreadPool   pThreadPool   =   new   IOCPThreadPool(0,   10,   20,   new   IOCPThreadPool.USER_FUNCTION(IOCPThreadFunction)); 
                        //for(int   i   =1;i <10000;i++)   
                        { 
                                pThreadPool.PostEvent(1234); 
                        } 

                        Thread.Sleep(100); 

                        pThreadPool.Dispose();   


              //       pulsesThread   =   new   Thread(new   ThreadStart(countPulses)); 
              //       pulsesThread.Start(); 
              
                    timer1.Enabled   =   true; 
                    btn_play.Enabled   =   false; 
                } 

                //********************************************************************   
                /**/ 
                ///   <summary>   Function   to   be   called   by   the   IOCP   thread   pool.     Called   when   
                ///                       a   command   is   posted   for   processing   by   the   SocketManager   </summary>   
                ///   <param   name="iValue">   The   value   provided   by   the   thread   posting   the   event   </param>   
        static       public   void   IOCPThreadFunction(int   iValue) 
                { 
        
                        try 
                        { 
                                do 
                                { 
              count   =   port.CtsHolding; 

                                        switch   (count) 
                                        { 

                                                case   true:   counttrue   =   true;   break; 


                                        } 

                                        if   (count   ==   false   &&   counttrue   ==   true) 
                                        { 
                                                switch   (direction) 
                                                { 

                                                        case   "1":   counttrue   =   false;   i++;   break; 
                                                        case   "2":   counttrue   =   false;   i--;   break; 

                                                } 

                                        } 


                                }   while   (stop   ==   1); 
                        } 

                        catch   (Exception   pException) 
                        { 
                                Console.WriteLine(pException.Message); 
                        } 
                }   


还有个问题!!!为什么我在上面明明定义了count,counttrue,stop...等等,在   static       public   void   IOCPThreadFunction(int   iValue)却用不了,要求从新定意????????????????????????? --------------------编程问答-------------------- 代码太乱,建议减少缩进(2个空格为宜),然后放到[code=C#]...[/code]中。 --------------------编程问答-------------------- 整理代码如下:
using System;   
using System.Collections.Generic;   

namespace rating   
{   
  public partial class DistancePulse : UserControl   
  {
    double i = 0;
    // ...
  }
}

然后再贴出来,人家才好帮你看。 --------------------编程问答-------------------- Error 2 An object reference is required for the nonstatic field, method, or property 'rating.DistancePulse.count' C:\Documents and Settings\liaorb\桌面\新建文件夹\Distance_pulse serial\Distance_pulse\DistancePulse.cs 258 8 Distance_pulse
--------------------编程问答-------------------- http://topic.csdn.net/u/20080214/09/a6ff5c33-9330-46b3-9b99-102604fea0ae.html

你看看这个吧 对于静态方法能访问什么样的成员 你需要好好了解下

--------------------编程问答-------------------- 怎么减少空格啊???有自动的吗???大虾 --------------------编程问答-------------------- 只能访问静态成员 --------------------编程问答-------------------- 那这个问题怎么解决啊!我去掉static就会没相应....加上又改变不了那些参数......郁闷 --------------------编程问答-------------------- 建议好好看看关于变量和访问和生存周期
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,