📜 ⬆️ ⬇️

Asynchronous programming in 1C via .Net Native VK

This is a continuation of the article. Cross-platform use of .Net classes in 1C through Native VK. Or replacing COM with Linux II

In .Net now in many classes there are asynchronous methods. In 1C they can be used for example

=(.GetStringAsync(uriSources)).Result; 

And let me remind you about the synonyms from the previous article / So adding a synonym
')
 .(HTTPClient.(),"","GetStringAsync"); .(Task.(),"","Result"); 

I can use everything in Russian

 =(.()).; 

But you can use asynchronous methods like this.

  = (.(HttpClient.(),handler.())); =("System.Collections.Generic.List`1[System.Threading.Tasks.Task]");     URL()  =(.GetStringAsync()); .Add(.()); ; Task=("System.Threading.Tasks.Task");  .Count>0  =(.ToArray());  = Task.WaitAny(.()); ();  = (.get_Item()).Result; (()); .RemoveAt(); ; 

This is of course not quite asynchronous programming, but it is still better than to call a synchronous method for each request separately.

But you need to make an asynchronous call. To do this, create a simple class.

 public class  {//    ,   ,       public object ; //   public Task ; //   1   . public String ; public (Task , String , Object ) { this. = ; this. = ; this. = ; .ContinueWith((t) => { var AW = new AutoWrap(this); AutoWrap.1("", , AW.()); }); } } 

And on the side of 1C:

  (,) =(ExpandoObject.()); .=; .=;  ;  // ()  ()  = (.(HttpClient.(),handler.())); =("System.Collections.Generic.List`1[System.Threading.Tasks.Task]"); =0;     URL()  //   =(.GetStringAsync()); //       =(,); //public static void (System.Threading.Tasks.Task , String , Object ) .(.(),"",.()); =+1; ; //     =("TestDllForCoreClr.","TestDllForCoreClr"); =(.(.(),"   ")); Thread=("System.Threading.Thread"); //   2   =(.Async(2)); =("Async",2); .(.(),"",.()); 2=(.Async(0)); =("Async",0); .(2.(),"",.());   ( ) =(.); =(.); ("="+.); ("="+.); //       // IsFaulted  ,   Exception    (.IsFaulted)  //   =.Exception; (" "+.()); //     1   .Exception   //       //   ,      // (" "+.(.Exception)); ; ; =.Result; (());   (, , ) //   . ("="+); ("="+); ("="+);  =""  =(); (+"()"); ;  

I will explain a little on the code.

Since in Native VK you cannot use the Add Processor, we will make its emulation by transferring the name of the method to be called in 1C to Asynchronous Performer.

 .(.(),"",.()); 

Which will be called when an external event is triggered.

   =""  =(); (+"()"); ; 

In this event variable, the ReceivedPage is stored and the method will be called.

 () 

Now, about using the External Event in .Net assembly

To do this, define the field

  public Action<string, string, string> 1; 

And install it from 1C.

 =("TestDllForCoreClr., TestDllForCoreClr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); =(.(.(),"   ")); =(.1C()); .1=.(); .Test(); 

Inside the .Net class call the method

 this?.1("", "", ); 

In this case, the procedure will be called in 1C.

  (, , ) ("="+); ("="+); ("="+);  


I tried to bring the C # syntax in 1C as close as possible. And for me, even in this form it is easier to write VK on C #, than to use the Native API on C ++. At the same time, you can integrate the use of .Net classes in 1C. By adding synonyms you can write everything in Cyrillic. You can add support for iterators, and so on.

Now there are a lot of ActiveX on Windows, and it’s not difficult to write a COM component in any language.
But it is not cross-platform.

Using .Net Core and this wrapper over .Net objects in 1C, you can significantly expand the capabilities of 1C using a huge number of libraries and classes in them. And focus on developing the language, finally adding a closure, Linq, specifying the type for intellisense (similar to TypeScript). Splitting modal dialogs in the same way as yeld and await in C #. As well as await analogs for server calls with closures.

I understand that this development is of little interest to anyone. But I was interested in developing it. In addition, it will be interesting to try .Net Core and use Reflection

Examples and sources can be downloaded here.

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


All Articles