将文件复制到远程服务器检查 [英] copy files to remote servers checks

查看:36
本文介绍了将文件复制到远程服务器检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约 100 个远程服务器,下面是我尝试复制一些文件的方式从我的电脑到所有这些远程服务器,但我想做一些检查

I Have around of 100 remote servers and below how I am trying to copy some files from my PC to all of these remote servers but I want to do some checks

1-检查与远程服务器的连接是否可用,如果不可用,则转到下一个办公室

1- check if the connection to remote servers is available if NOT then go to next office

2-用于用户交互

a- 我正在尝试为 datagridview1 中的选定行着色,让用户知道现在的进度和 datagridview2 相同的事情让用户知道现在在哪个文件的进度在特定的办公室,但开始发送文件后界面冻结并且没有交互发生怎么办?

a- I am trying to color selected row at datagridview1 to let user know at whcih office the progress is now and alos at datagridview2 the same thing to let user know at which file the progress is now at specific office but the interface freeze after starting sending file and no interaction happen what to do ?

b-如果成功,如何将完成的办公室行着色为绿色?

b-how to color finished office row at green if success ?

更新

我使用线程来解决表单冻结问题,以便反馈会返回给用户但问题没有解决,仍然发生,没有任何改变,请问我该怎么办???

I used threading to solve form freezing so the feedback will back to user but problem not solved and still happen and nothing change please what should i do ???

public void PatchUpdates()
{
    try
    {
        foreach (DataGridViewRow OfficeListRow in DGV_OfficeList.Rows)
        {
            string OfficeIPAddress = OfficeListRow.Cells[2].Value.ToString();

            foreach (DataGridViewRow FileListRow in DGV_FileList.Rows)
            {
                string SoruceFileNamePath = FileListRow.Cells[4].Value.ToString();
                string DestinationFileNamePath = @"\\" + OfficeIPAddress + @"\usb1_1\test\" + Path.GetFileName(SoruceFileNamePath);


                Thread foregroundthread = new Thread(() => CheckOffice(OfficeIPAddress));

                foregroundthread.Start();

                //check if connection to remote server is available
                if (CheckOffice(OfficeIPAddress) == 1)
                {
                    DGV_OfficeList[3, DGV_OfficeList.CurrentCell.RowIndex].Value = "Connected";
                    //file.copy(sorucefilenamepath, destinationfilenamepath, true); //copy files...
                }
                else if (CheckOffice(OfficeIPAddress) == 0)
                {
                    DGV_OfficeList[3, DGV_OfficeList.CurrentCell.RowIndex].Value = "disconnected";
                    break;
                }
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

检查连接方式

public int CheckOffice(string _ipAddress)
{
    int timeout = 120;
    string data = "PingTestData";
    byte[] buffer = Encoding.ASCII.GetBytes(data);

    Ping PingSender = new Ping();
    PingOptions options = new PingOptions();

    options.DontFragment = true;

    PingReply reply = PingSender.Send(_ipAddress, timeout, buffer, options);

    if (reply.Status == IPStatus.Success)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

推荐答案

我猜测 PatchUpdates 是从 GUI 线程调用的.如果您在复制文件的循环中更新 DataGridViewRow.Selected,则 GUI 将永远不会反映该更改,因为您的函数尚未返回.有几种方法可以解决.

I am guessing that PatchUpdates is called from the GUI thread. If you update the DataGridViewRow.Selected in the loop where you are copying the files, then the GUI will never reflect that change, wince your function has not yet returned. There are a few ways to deal with it.

  1. (Hackiest,但最快)在 DataGridViewRow.Selected 更改后调用 Application.DoEvents()
  2. (更简洁的解决方案,但需要更多努力)在后台线程中执行此处理并切换到 GUI 线程以使用 Control.BeginInvoke() 方法更新 GUI.
  1. (Hackiest, but quickest) Call Application.DoEvents() after the DataGridViewRow.Selected change
  2. (Cleaner solution but more efforts) Do this processing in a background thread and switch to GUI thread to update the GUI using the Control.BeginInvoke() method.

除此之外,您的代码还有很多问题:

Now other than this, there are bunch of issues in your code:

下面的行不会改变,但会循环调用以不断检查您的网络连接是否断开.它可能是你真正需要的,但它有点像一个错误.也许您想使用 Ping 类来检查机器是否可用?

The below line does not change, but is called in a loop to constantly check if your network connection is dropped or not. It might be what you actually need, but it kind of stood out as a mistake. Perhaps you want to use the Ping class to check if the machine is available?

if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())

您刚刚切换了值,可能没有任何原因.也许您只是想调试您的解决方案.或者,也许您实际上希望该行闪烁,但是此代码不会发生这种情况

You have just toggled the value, probably for no reason. Maybe you were just trying to debug your solution. Or maybe you actually wanted the line to flash, but that won't happen with this code

OfficeListRow.Selected = true;
OfficeListRow.Selected = false;

这篇关于将文件复制到远程服务器检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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