简体   繁体   English

如何调用WCF服务中定义的进度条-C#

[英]How to call progress bar defined in wcf service - c#

I have a client(WinForms Application)/Server (WCF Service) where I am doing some complex logic which writes packets to a remote host - this process takes about 20 minutes to write to a specific point but does not complete. 我有一个客户端(WinForms应用程序)/服务器(WCF服务),在其中执行一些复杂的逻辑,该逻辑将数据包写入远程主机-此过程大约需要20分钟才能写入到特定点,但未完成。 So I want to show progress and attempt to continue from where I last stopped in my client application in the form of a progress bar. 因此,我想以进度条的形式显示进度,并尝试从上次停止在客户端应用程序中继续执行。

  //Service:
  public class ServiceImplementation: IServiceInterface{
    ProgressBar pgBar = new ProgressBar();

  public void complexFunction(byte[] data_to_send, UInt32 start_addr){
     pgBar.Maximum = data_to_send.Length;
     for(int i = 0; i < data_to_send.Length; i += 64){
      //do some logic
     }
      pgBar.Value = i;
   }
 }

 //Client
  private void btnProgComplexFunction_Click(object sender, EventArgs e){
     callComplexFunction
  }

  void callComplexFunction(){
     ServiceImplementation.ServiceImplementationClient proxyInstance = new 
    ServiceImplementation.ServiceImplementationClient();

    //I attempted doing the following but obviously it doesn't work because progress bar returns an integer (e.g pgBar.Value = 100;). The problem lies here. I have been cracking my skull for two days straight
    pgBar.Value = proxyInstance.complexFunction(data_to_send, start_addr);}

You need to async call to your web service. 您需要异步调用Web服务。 Also need to soap client to this. 还需要给客户肥皂。 You can achive it with download progress feature to do this. 您可以使用下载进度功能来实现。

You can check this article. 您可以查看这篇文章。

http://shenoyatwork.blogspot.com.tr/2006/10/showing-download-progress-with-net.html http://shenoyatwork.blogspot.com.tr/2006/10/showing-download-progress-with-net.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM