English 中文(简体)
采用多管齐下
原标题:application redundancy with multithreading

我们正在尝试为窗户撰写一份服务书,并需要制定 red余计划,这样,如果申请中的一些内容失败,就会再次收回。 i m 想知道,我是否能够利用多面办法实现这一目标。

my idea is to create two threads which each handle separate tasks. i would like to also have each thread monitor the other thread to make sure its still running, if its not, then it should start up a new instance of that thread. does this sound feasible? what threading techniques would i use: mutexes, shared memory, semaphores, etc...? if this is not the correct approach, then what might be, just write two separate services and use IPC?

最佳回答

Well the easiest way to get your service to restart on failure is to let Windows do it. You just configure the service to auto restart, its really easy. You can also do this programatically durring the service installer. For a guide on how to do this, see this post: Building a Windows Service – Part 4: Extending the Service Installer.

至于这一规定,这并不是“多余”。 对裁员的适当定义意味着你有不止一个。 这可能使用多种服务,或更可能使用多个东道国的多种服务。 在单一东道国提供多种服务比较容易,因为如果需要,你可以使用一种调子来同步。

真正的问题是这一服务是做的?

If your service is polling for tasks, say from a database or message queue, then the synchronization is taken care of for you. Just model your database such that multiple services can all run and process work independently without duplicating work. Now you have redundancy.

问题回答

Yes, that sounds like a feasible solution. The only problem with double threads is that if the application crashes then both threads will die (if they are background threads) The solution I found useful to this problem is to have a watchdog process. Whenever the worker process crashes, the watchdog kicks in and creates a new instance and runs it.

你只能把申请写成视窗服务局使用的一类图书馆(视力演播室的插板,你需要添加安装器)。 如果你以这种方式提出申请,你将随时选择确定行为,如果事情失败,则永远重新开始,重新开两倍,并在电子邮件发出后再接手或管理其他申请等。

It s built into any windows box you have credentials for and all the hard work is done for you. It s always a no brainer for services I need to always be up and running.

为了做到这一点,你将服务类型设定为自动服务类型(如果你的箱子重新boot,这种服务类型将重新启用),那么,在服务科,在头三个重新启用时,需要选择:在内。

more info: windows service documentation

我发现,涵盖各种案件的最有力的解决办法是开展监督工作,可以启动并停止工人进程。 你们将利用世界合作框架发出信号(或其他信息),在进程之间发出信号。 想法是使监督过程简单化,这样,在履行其有限的一系列任务时,几乎没有可能失败。 然后将所有风险逻辑引入工人进程。

起草一项议定书,将工人的失败或健康告知监督过程。 这里有几个想法。 这份清单绝非详尽无遗。

  • Watchdog restarts worker process if it does not receive a status report in timely manner.
  • Watchdog restarts worker process if it receives a failure status report.
  • Watchdog restarts worker process if it detects a memory leak.
  • Watchdog starts worker process if it is not running.

除了最后一个项目外,Windows服务控制经理不能处理其他3起案件。 这就是为什么我喜欢看望进程的想法。 另一个原因是,你的主逻辑可能会被 call倒。 自Thread.Abort <>/code> 以来,由于腐败,你实际上只有很少选择,只是要杀工人。

此外,试图使你的主要逻辑尽可能容忍过错。 那么,如果你确实需要强行终止,那就非常容易收回和清理留下的物品。 这可能意味着使用诸如非行交易或单项档案业务等原子业务。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...