简体   繁体   English

C#.net应用程序中的分叉线程死掉并且没有引发任何错误

[英]Forked thread in C# .net App dies inexplicably and without throwing any errors

Firstly, I am sorry if this is quite a vague question, it is quite difficult to explain and quite bizarre and it also does not seem like a particularly specific problem. 首先,很抱歉,如果这是一个模糊的问题,很难解释,也很奇怪,这似乎也不是一个特别具体的问题。 but I will do my best to explain here: 但我会尽力在这里解释一下:

I have a C# .net application which forks a new thread to do most of it's work - with the primary thread just handling a GUI front end. 我有一个C#.net应用程序,该应用程序派生了一个新线程来完成大部分工作-主线程仅处理GUI前端。

syncThread = new Thread(new ThreadStart(syncClass.sync));

The sync thread loops continuously... 同步线程不断循环...

public void sync()
    {

        while (true)
        {
           do stuff

And at the end, has a sleep to stop it hogging CPU all of the time... 最后,要有睡眠来阻止它一直占用CPU。

System.Threading.Thread.Sleep(sync_interval);

To fill in some background, what it does in "do stuff" is connect to Sage using Sages API, and connect to a SOAP service and basically pull data from Sage and push to the SOAP. 为了填充一些背景知识,它在“做事”中的工作是使用Sages API连接到Sage,并连接到SOAP服务,并且基本上是从Sage中提取数据并推送到SOAP。 This works fine HOWEVER... 这很好,但是...

What appears to be happening is that at random intervals the thread just stops executing - as though it has just "gone away". 似乎正在发生的事情是,线程以随机的间隔停止执行-好像它已经“消失了”。 I have logged to screen and to a file to try and find a particular cause for this but it stops at different parts of it's process almost every time. 我已登录到屏幕和文件以尝试查找引起这种情况的特定原因,但是几乎每次都在过程的不同部分停止它。

I have tried catching errors and logging these to screen and to file as well as logging code execution progress to file - but when this happens - it simply does not throw an error (or if it does, I am not able to catch it). 我尝试捕获错误并将它们记录到屏幕和文件中,以及将代码执行进度记录到文件中-但是,当发生这种情况时-它根本不会引发错误(或者如果发生错误,我将无法捕获)。 So I am completely stuck. 所以我完全被困住了。

To add to the bizarreness - this does not seem to happen on every system it is installed on but does happen on more than just the odd one. 更奇怪的是,这似乎并没有在安装的每个系统上发生,但确实发生在不只是奇数系统上。

Without any caught errors to fix, and no set area of code to investigate for the problem (because as I say - it is not consistent) I am completely stumped as to how to proceed. 没有任何捕获到的错误可修复,也没有固定的代码区域可用来研究问题(因为我说过-不一致),我完全困惑如何进行。

So - are there any general threading issues that anyone is aware of that could cause this behaviour? 那么-是否有任何人知道的常规线程问题会导致这种行为? Is there a better way for me to go about the threading in the first place, or can anyone offer any further advice on how to find and trap the error so that I can fix it? 首先,有没有一种更好的方法可以使我着手进行线程处理,或者任何人都可以就如何查找和捕获错误提供任何进一步的建议,以便我可以对其进行修复?

Please help :) 请帮忙 :)

If you are talking to Sage 50 via the SDO it's a COM interface and it runs in a Single Threaded Apartment (STA), I am 99% sure that your app too will have to run in STA mode - our app runs as as a STA and if I recall we only thread the UI elements. 如果您通过SDO与Sage 50交谈,它是一个COM接口,并且在单线程单元(STA)中运行,那么我99%的确定您的应用程序也必须以STA模式运行-我们的应用程序将以STA身份运行如果我还记得的话,我们只线程UI元素。

Try sticking [STAThread] in your Main() function and see if that helps - Let me know how you get on. 尝试将[STAThread]粘贴到Main()函数中,看看是否有帮助-让我知道您的情况。

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

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