{"title":"增强客户端应用程序中的线程安全控制调用","authors":"R. Gibadullin","doi":"10.7256/2454-0714.2022.4.39029","DOIUrl":null,"url":null,"abstract":"\n When the first version of the .NET Framework was released, there was a pattern in enriched client applications that focused on message processing loops, where an embedded queue was used to pass execution units from worker threads. A generalized ISynchronizeInvoke solution was then developed in which the source thread could queue a delegate to the destination thread and, as an optional option, wait for that delegate to complete. After asynchronous page support was introduced into the ASP.NET architecture, the ISynchronizeInvoke pattern did not work because asynchronous ASP.NET pages are not mapped to a single thread. This was the reason for creating an even more generalized solution – SynchronizationContext, which is the subject of the research. The article uses practical examples to show how to update UI elements from worker threads without breaking thread-safety of the user application. Solutions proposed in this aspect are: using Beginlnvoke or Invoke methods to put this delegate into the UI thread message queue; capturing the UI thread synchronization context via the Current property of the SynchronizationContext class; using the deprecated BackgroundWorker class, which provides an implicit capture of the UI thread synchronization context. The peculiarity of implementation of the SynchronizationContext abstract class in ASP.NET platform is not left unnoticed. Practical recommendations on the use of marshalling mechanism on the example of development of multiclient chat with a centralized server are formulated.\n","PeriodicalId":155484,"journal":{"name":"Программные системы и вычислительные методы","volume":"1 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2022-04-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"2","resultStr":"{\"title\":\"Thread-safe Control Calls in Enriched Client Applications\",\"authors\":\"R. Gibadullin\",\"doi\":\"10.7256/2454-0714.2022.4.39029\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"\\n When the first version of the .NET Framework was released, there was a pattern in enriched client applications that focused on message processing loops, where an embedded queue was used to pass execution units from worker threads. A generalized ISynchronizeInvoke solution was then developed in which the source thread could queue a delegate to the destination thread and, as an optional option, wait for that delegate to complete. After asynchronous page support was introduced into the ASP.NET architecture, the ISynchronizeInvoke pattern did not work because asynchronous ASP.NET pages are not mapped to a single thread. This was the reason for creating an even more generalized solution – SynchronizationContext, which is the subject of the research. The article uses practical examples to show how to update UI elements from worker threads without breaking thread-safety of the user application. Solutions proposed in this aspect are: using Beginlnvoke or Invoke methods to put this delegate into the UI thread message queue; capturing the UI thread synchronization context via the Current property of the SynchronizationContext class; using the deprecated BackgroundWorker class, which provides an implicit capture of the UI thread synchronization context. The peculiarity of implementation of the SynchronizationContext abstract class in ASP.NET platform is not left unnoticed. Practical recommendations on the use of marshalling mechanism on the example of development of multiclient chat with a centralized server are formulated.\\n\",\"PeriodicalId\":155484,\"journal\":{\"name\":\"Программные системы и вычислительные методы\",\"volume\":\"1 1\",\"pages\":\"0\"},\"PeriodicalIF\":0.0000,\"publicationDate\":\"2022-04-01\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"2\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"Программные системы и вычислительные методы\",\"FirstCategoryId\":\"1085\",\"ListUrlMain\":\"https://doi.org/10.7256/2454-0714.2022.4.39029\",\"RegionNum\":0,\"RegionCategory\":null,\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"\",\"JCRName\":\"\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"Программные системы и вычислительные методы","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.7256/2454-0714.2022.4.39029","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 2
摘要
当. net Framework的第一个版本发布时,在富客户端应用程序中有一种模式专注于消息处理循环,其中使用嵌入式队列来传递来自工作线程的执行单元。然后开发了一个通用的isynsynchronizeinvoke解决方案,其中源线程可以将委托排队到目标线程,并作为可选选项等待该委托完成。异步页面支持被引入ASP。. NET体系结构中,isynsynchronizeinvoke模式不起作用,因为异步ASP。. NET页不映射到单个线程。这就是创建一个更通用的解决方案的原因——SynchronizationContext,这也是本研究的主题。本文使用实际示例来展示如何在不破坏用户应用程序线程安全的情况下从工作线程更新UI元素。在这方面提出的解决方案是:使用begininvoke或Invoke方法将此委托放入UI线程消息队列;通过SynchronizationContext类的Current属性捕获UI线程同步上下文;使用已弃用的BackgroundWorker类,它提供了对UI线程同步上下文的隐式捕获。ASP中SynchronizationContext抽象类实现的特点。. NET平台并没有被忽视。在使用集中式服务器开发多客户机聊天的示例中,给出了使用编组机制的实用建议。
Thread-safe Control Calls in Enriched Client Applications
When the first version of the .NET Framework was released, there was a pattern in enriched client applications that focused on message processing loops, where an embedded queue was used to pass execution units from worker threads. A generalized ISynchronizeInvoke solution was then developed in which the source thread could queue a delegate to the destination thread and, as an optional option, wait for that delegate to complete. After asynchronous page support was introduced into the ASP.NET architecture, the ISynchronizeInvoke pattern did not work because asynchronous ASP.NET pages are not mapped to a single thread. This was the reason for creating an even more generalized solution – SynchronizationContext, which is the subject of the research. The article uses practical examples to show how to update UI elements from worker threads without breaking thread-safety of the user application. Solutions proposed in this aspect are: using Beginlnvoke or Invoke methods to put this delegate into the UI thread message queue; capturing the UI thread synchronization context via the Current property of the SynchronizationContext class; using the deprecated BackgroundWorker class, which provides an implicit capture of the UI thread synchronization context. The peculiarity of implementation of the SynchronizationContext abstract class in ASP.NET platform is not left unnoticed. Practical recommendations on the use of marshalling mechanism on the example of development of multiclient chat with a centralized server are formulated.