using System;
using System.Windows;
using System.Windows.Forms;
using System.Threading;
using System.Data;
using System.Data.OracleClient;namespace affairMonitor
{
/// <summary>
/// 事务监视以及主菜单下拉按钮列
/// </summary>
public class affairMenuItem 
{
System.Drawing.Icon icon1;
System.Drawing.Icon icon2;
string m_ConnectionString;  private System.Windows.Forms.NotifyIcon m_NotifyIcon;
private bool flag;
private bool m_flash ;
static ThreadStart m_threadStart;
static Thread m_thread;
public affairMenuItem(string connectionString)
{
this.m_ConnectionString = connectionString;
m_NotifyIcon = new NotifyIcon();
System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream file1 = thisExe.GetManifestResourceStream("affairMonitor.MAIL01B.ICO");
icon1 = new System.Drawing.Icon(file1);
System.IO.Stream file2 = thisExe.GetManifestResourceStream("affairMonitor.MAIL02A.ICO");
icon2 = new System.Drawing.Icon(file2);

m_flash = false; //此处其实没什么意义
this.flag = true; // m_NotifyIcon.Icon = icon;
file1.Close();
file2.Close();
m_NotifyIcon.Text = "";
m_NotifyIcon.Visible = false;
m_NotifyIcon.Click+=new EventHandler(m_NotifyIcon_Click);
                           m_NotifyIcon.DoubleClick+=new EventHandler(m_NotifyIcon_Click);
}

/// <summary>
/// 调用任务栏实时监视唯一需要执行的方法
/// </summary>
/// <param name="ParaForm">欲添加notify的winform窗体</param>
public void NeedNotify( System.Windows.Forms.Form ParaForm )
{
m_NotifyIcon.Icon = this.icon1;
m_NotifyIcon.Visible = true;
// StartMonitor();
}

/// <summary>
/// 启动实时监视线程
/// </summary>
public void StartMonitor()
{
m_threadStart = new ThreadStart( (new affairMenuItem(this.m_ConnectionString)).wheelInquire );
m_thread =new Thread( m_threadStart ); 
m_thread.Start();
} /// <summary>
/// 轮询主函数
/// </summary>
public void wheelInquire()
{
while( flag )
{
string myConnString = this.m_ConnectionString;
OracleConnection myConnection = new OracleConnection(myConnString);
OracleCommand catCMD = myConnection.CreateCommand();
catCMD.CommandText = " SELECT count(*) as count FROM affair_in";
myConnection.Open();
OracleDataReader myReader = catCMD.ExecuteReader();
while (myReader.Read())
{
if( myReader["count"].ToString() != "0" )
{
notifyFlash();
}
} myReader.Close();
myConnection.Close(); Thread.Sleep(60000); //1 minute
}


m_NotifyIcon.Visible = false;
}
public void notifyFlash()
{
m_NotifyIcon.Visible = true;
int i = 1;
m_flash = true;
while( this.m_flash )
{
if( i>0 )
{
m_NotifyIcon.Icon = this.icon1;
}
else
{
m_NotifyIcon.Icon = this.icon2;
}
i *= -1;
Thread.Sleep(1000);
}
}

private void m_NotifyIcon_Click(object sender, EventArgs e)
{
this.m_flash = false;
this.m_NotifyIcon.Visible = false;
} }
}完全代码如上,单击和双击都委托到最后面这个方法里了,但是调试时进入不了

解决方案 »

  1.   

    加个断点,看看m_NotifyIcon.Click+=new EventHandler(m_NotifyIcon_Click);
    m_NotifyIcon.DoubleClick+=new EventHandler(m_NotifyIcon_Click);
    这两句话有没有运行。应该不是多线程的关系。
      

  2.   

    运行了,但是在命令窗口里 查看,如下:
    this.notifyIcon1.Click
    错误:“this.notifyIcon1.Click”不存在
      

  3.   

    this.notifyIcon1.Click
    为什么提示信息是notifyIcon1
    而不是这个m_NotifyIcon呢。我在你的代码里面确实没有找到这个东西啊。
      

  4.   

    change 
    m_NotifyIcon = new NotifyIcon();with
    m_NotifyIcon = new NotifyIcon(this.components);
      

  5.   

    必须把m_NotifyIcon 加到该程序组件中去
      

  6.   

    我是http://community.csdn.net/Expert/topic/4691/4691225.xml?temp=.8598139
    的LZ,应邀来JF