Timer刷新问题

AwL_1124 AwL_1124 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
功能:
用定时器,每隔多少秒刷新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控件中
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
AwL_1124
VC.NET 7,538 成员 27,670 内容