如何让应用程序运行多个进程,每个进程使用一个单独的 XML 设置文件? [英] How to make the application run several processes, each of which used a separate XML settings file?

查看:25
本文介绍了如何让应用程序运行多个进程,每个进程使用一个单独的 XML 设置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个条件示例.
有:
- 带有设置的文件(文件同样"):
- ..\01\setting\fold_1\settings_1.xml
..\01\setting\fold_2\settings_2.xml
..\01\setting\fold_3\settings_3.xml
- 数据文件(用于例如(文件数据")):
..\01\数据\fol_data_1\fol_data_1.txt
..\01\数据\fol_data_2\fol_data_2.txt
..\01\数据\fol_data_3\fol_data_3.txt

I made a conditional example.
There are:
- files with settings (file "Likewise"):
- .. \ 01 \ setting \ fold_1 \ settings_1.xml
.. \ 01 \ setting \ fold_2 \ settings_2.xml
.. \ 01 \ setting \ fold_3 \ settings_3.xml
- data files (used for example (file "Data")):
.. \ 01 \ data \ fol_data_1 \ fol_data_1.txt
.. \ 01 \ data \ fol_data_2 \ fol_data_2.txt
.. \ 01 \ data \ fol_data_3 \ fol_data_3.txt

设置"文件显示在树视图中.当您将焦点移到树上时,所有设置都会根据文件显示在表单字段中.示例中的设置数量通常被接受.实际上,该示例使用文件数据"设置数据"(textBox4)".那些.在每个settings_N.xml"中对应的Data"文件的路径.

The "Settings" files are displayed in the tree view. When you move the focus to the tree, all settings are displayed in the form fields depending on the file. The number of settings in the example is conventionally accepted. In fact, the example uses the "File data" setting "Data" (textBox4) ". Those. in each "settings_N.xml" the path to the corresponding "Data" file.

场景.

  1. 用户.在树中选择一个或多个Likewise"文件;

  1. The user. Selects one or more "Likewise" files in the tree;

通过勾选 CheckBox 证书为true"来做出选择;

The choice is made by checking the CheckBox certificate to "true";

  1. 用户.点击运行"按钮(button3);
  2. 程序.在每个数据"文件的tabControl"中创建一个单独的选项卡;(在这个例子中,没有使用tabControl")

  1. The user. Click "Run" button (button3);
  2. The program. Creates a separate tab in the "tabControl" of each "Data" file; (in this example, "tabControl" is not used)

程序.为每个文件Data"创建表DateTable;

The program. Creates tables DateTable for each file "Data";

必须同时为所有选定的Nystroka"文件执行第 4 - 7 项.在此示例中,运行"按钮 (button3) 仅针对一个数据"文件执行脚本.

Items 4 - 7 must be executed simultaneously for all selected "Nystroka" files. In this example, the "Run" button (button3) executes the script for only one "Data" file.

我怀疑这应该通过多线程"(Thread)来完成,但我不知道如何处理它.

I suspect this should be done by means of "multithreading" (Thread), but I can not figure out how to approach it.

或者有其他方法吗?

问题.

  1. 如何实现这个场景?
  2. 如何组织课程?

Form1.cs
代码 - link

项目 - 链接

Pic_1
Pic_2

推荐答案

我会说使用 BackgroundWorker 吗?!

I would say use a BackgroundWorker ?!

这是一个很好的例子的链接,如果需要,我会自己提供一个例子.BackGroundWorkder 示例

Here is a link with a nice example, if needed I will provide a example myself. BackGroundWorkder Example

这是给你的一个小例子

private void MethodForWorker()
{
    BackgroundWorker worker = new BackgroundWorker();
    // This is where we create the event that will run on the background, not blocking the main thread
    worker.DoWork += this.Worker_DoWork;
    // This is where we create the event that will run after the backgroun as finished doing its work, this is not necessary per say, only if you need for it to run something after the background work is done
    worker.RunWorkerCompleted += this.Worker_RunWorkerCompleted;
    // To start the background work
    worker.RunWorkerAsync();
}

private void Worker_DoWork(object sender, DoWorkEventArgs e)
{
    // This is where you put the code that will run on the background
    // Remenber, to send stuff to the main thread you must use the invoke
    this.Invoke(new Action(() =>
    {
        // Code of what you need to pass to the main thread, for example to use a MessageBox or to update a label ? up to you if you need to do stuff on the main thread
    }));
}

private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    // This is where you put the code that will run after the Worker_DoWork has finnish doing all is job
}

这篇关于如何让应用程序运行多个进程,每个进程使用一个单独的 XML 设置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆