Monotouch, GC, WCF streams

This is a question about best practices that I suppose, but it relates directly to my current MT project.

I use WCF services to communicate with the server.

To do this, I do the following:

services.MethodToCall(params);

and asynchronous:

services.OnMethodToCallCompleted += delegate{
    //do stuff and ting
};

This can lead to problems if you are not careful that the variables defined in the asynchronous callback area can sometimes be cleared by gc, and this can lead to crashes.

So, I make it a practice to declare them outside the callback scope if I'm not sure if they are not needed.

Now - when you are doing something, and ting implies a change in ui - i, we complete all this in the InvokeOnMainThread call. I assume that wrapping everything in this will slow the main thread down and overwrite the point with multiple threads.

, , , , !

, - , .

- , , InvokeOnMainThread, , " ". 5 http://www.yoda.arachsys.com/csharp/singleton.html

, , / - InvokeOnMainThread.

- .

... :

dev - -, :)

, , , ?

? - ?

://

+3
1

FYI, , , ( ). , , , GC , , , .

, - .

.

+1

Source: https://habr.com/ru/post/1745068/


All Articles