Timer刷新问题

AwL_1124 2011-10-10 02:23:06
功能:
用定时器,每隔多少秒刷新path下文件内容到Textbox
VS2010的Windows Froms Application
这是在button1_Click中的方法
 			 //调用刷新方法来定时分析数据
refrushClass^ re = gcnew refrushClass;
path = "c:\\SceneServer.log5696";
re->Main(path);

refrushClass类(与public ref class Form1 : public System::Windows::Forms::Form在同一源码中):

public ref class refrushClass
{
private:
static System::Windows::Forms::Timer^ myTimer = gcnew System::Windows::Forms::Timer;
static int alarmCounter = 1;
static String^ pathRefrush;
static String^ strTotal;
// This is the method to run when the timer is raised.
static void TimerEventProcessor( Object^ /*myObject*/, EventArgs^ /*myEventArgs*/ )
{
myTimer->Stop();
myTimer->Enabled = true;
//读取path文件内容
StreamReader^ sr = File::OpenText(pathRefrush);
try
{
//临时存放每次读取到的文件
String^ s = "";
while (s = sr->ReadLine())
{
strTotal += s;
}
}
finally
{
if (sr)
{
//释放缓存文件
delete (IDisposable^)(sr);
}
}
/*不知道怎么把strTotal传递到指定的textbox中,textbox无法直接在此引用*/
}


public:
static void Main(String^ path)
{
pathRefrush = path;
/* Adds the event and the event handler for the method that will
process the timer event to the timer. */
myTimer->Tick += gcnew EventHandler( TimerEventProcessor );

// Sets the timer interval to 5 seconds.
myTimer->Interval = 5000;
myTimer->Start();

// 调用TimerEventProcessor()方法
while(true)
{
Application::DoEvents();
}
}
};

设计思路:
通过TimerEventProcessor方法来定时读取Path中的内容,但不知道如何传递到textbox控件中
...全文
96 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
真相重于对错 2011-10-10
  • 打赏
  • 举报
回复
弄一个form1 的全局变量

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧