创建一个静态数据更新过程 [英] create a static data update process
本文介绍了创建一个静态数据更新过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要执行以下操作
创建一个名为sindhu
的新C#类
此类中将是一个公共方法LoadXMLData(),该方法可以向用户报告数据更新成功还是失败.
将从我们在屏幕中创建的按钮中调用它.
Ho to do the following
create a new C# class called sindhu
In this class will be a public method LoadXMLData() which can report to the user if the update of the data is succeeded or failed.
It will be called from a button in the which we create in a screen
推荐答案
在VS中右键单击项目名称.
选择添加...类".
将其命名为"sindhu",然后按OK
对其进行修改,使其为静态.
添加您的公共静态方法,返回一个布尔值,或者创建一个成功和失败的事件,并在进行任何后台处理时发出相应的信号.
如何创建事件.这就是我被打动的地方?单击我创建的按钮时应调用此事件".
一个事件很容易构造:
Right click the project name in VS.
Select "Add...Class".
Name it "sindhu" and press OK
Modify it so that it is static.
Add your public static method, either returning a bool value, or create a succeeded and a failed event and signal the appropriate one if you do any background processing.
"how to create the event..this is where I''m getting strucked??and this event should be called when I click on a button which I create"
An event is pretty easy to construct:
public static class sindhu
{
public static event EventHandler Success;
private static void OnSuccess(EventArgs e)
{
EventHandler eh = Success;
if (eh != null)
{
eh(null, e);
}
}
}
但是您不调用"一个事件,而是提供一个在信号通知该事件时调用的处理程序:
But you don''t "call" an event, instead you provide a handler which is called when the event is signalled:
sindhu.Success += new EventHandler(sindhu_Success);
...
void sindhu_Success(object sender, EventArgs e)
{
... // Do something on success.
}
这篇关于创建一个静态数据更新过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文