如何使用线程在按钮单击事件上调用相同的方法 [英] How to call same method on button click event using thread

查看:73
本文介绍了如何使用线程在按钮单击事件上调用相同的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

i有一个Web应用程序,其中包含带有3个按钮的web表单。所有3个按钮的按钮点击事件生成PDF文件的相同方法被调用一个参数。我想要使我的方法(PDFGenerating)是线程安全的,所以如果用户同时点击所有三个按钮数据不能得到混合。

i希望方法应该逐个调用。

即第一个pdf文件将为btn1生成一次完成btn2 thn for btn3的文件。我希望同步使用相同的方法使用线程。



请帮助我。



代码示例: -

Hi All,
i have an one web application which consist web form with 3 button.onbutton click event for all 3 button same method for generating PDF file is getting called with one parameter.i want to make my method(PDFGenerating) is thread safe so if useer click all three button at same time data can not be get mixup.
i want methos should be getting call one by one.
i.e first pdf file will be generting for btn1 once completed file for btn2 thn for btn3. i want Synchronization for same method using thread.

Please help me on this.

code example:-

protected void bthSubmit1_Click(object sender, EventArgs e)
      {
                   PDFGenerating("2");
      }
      protected void bthSubmit2_Click(object sender, EventArgs e)
      {
                 PDFGenerating("3");
      }
      protected void bthSubmit3_Click(object sender, EventArgs e)
      {
                  PDFGenerating("4");
      }

protected void PDFGenerating(string id)
  {
//Code for PDF file 
}



请帮帮我。



提前致谢


Please help me on this.

Thanks in advance

推荐答案

您说这些按钮存在于网页中。网页事件发生在页面加载生命周期的特定时间。



当您提交表单时,页面将被加载,然后发生事件。这意味着你只需要用每个按钮提交一次表格。



你可以通过使用更新面板解决这个问题,这些面板会在没有重新加载的情况下回发表单。



回发事件确实以事件 s的形式发生,因此无论如何每个都将在一个单独的线程上运行。解决此问题的唯一方法是,如果您有共享资源,例如静态字段。



如果您遇到特定问题,请回复详细信息那个问题我会进一步调查



希望有所帮助^ _ ^

Andy
You say that these buttons exist in a web page. Web page events happen at a particular time in the page load life cycle.

When you submit a form, the page is loaded and then the events take place. This means that you will only submit the form once with each button.

You can get around this by using update panels which would post back the form without reloading it.

The post back event do occur as events so each will run on a separate thread anyway. The only way that you would hit this problem is if you have a shared resource such as a static field.

If you are experiencing a specific issue then reply with the details of that problem and I will investigate further

Hope that helps ^_^
Andy


这篇关于如何使用线程在按钮单击事件上调用相同的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆