c# - WCF Service Begin method calls Background worker -


I know that information about this has spread to the whole internet, but I can not find any special solution for my scenario Could

I am using .NET 4.5 VS 2012

I have created a WCF service

  #region ISampleService member public IAsyncResult BeginServiceMethod (String msg, Async callback callback, object asyncState) {Thread.Sleep (10 * 1000); Newly completed asynchronous result & lt; String & gt; (msg.ToUpper ()); } Public String End Service Manager (IAsyncResult Results) {Completed Synonyms & lt; String & gt; res = Asyncrasult completed as a result & lt; String & gt; Return Ridge Data; } #ndrion   

What I now have to do is call any other method from BeginServiceMethod , which eventually starts to take a background worker action I want to continue execution of EndServiceMethod on the event completed on the background worker.

I do not know whether it is possible or not or is it a good design or not. Actually, I came to the problem when the old structure was migrated to the new framework and just wanted to make some improvements in the design.

[edit] In other words, I can say that I have to plug into my actions between the initial X and the endx methods.

This MSDN blog post

The summary of the article is as follows: Call / implement asynchronous pattern, then these are two principles: Principle 1: Do not do heavy weighted work (which starts from above) within the initial method. The reason for this is that you should return the calling thread as soon as possible so that the caller can schedule another job. If this is a UI thread, then the user needs to use the thread to answer the input. You should always do heavy operations at different threads if possible.

A1: Principle 2: Avoid calling and method (which is endowwork above) on a thread similar to the start method. The termination method is generally blocked, it waits for the operation to complete. If you apply the End method, you will see that it actually calls IAsyncResult.WaitHandle.WaitOne (). On the other hand, as a general implementation (for example, the sample attached to this blog entry), this waitHandle has a delayed allocated manual from the event. Until you call it, it will not be allocated. For faster operation, it is very cheap though, in the end it is said once, you have to allocate it. The right place to call the end is from the callback of the operation. When callback is implemented, this means that the blocking work is actually completed. At this point, you can call the end to get the data without sacrificing the display. Note that the above post is a bit dated, since you are using net 4.5, you can also wait for async pattern.

You use the Task Parallel Library (TPL) can also start a thread: Task.Factory.StartNew () ... when you use TPL based async operations in WPL (.net 4.0+)

If you You can not use TPL-based operations, then you can use a representative who uses the same API Invite a BigBin with.

Ask me if you want to be described in the way described above, I did not write to them because you will get lots of articles on the net.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -