日期:2014-05-17 浏览次数:21052 次
AutoResetEvent[] are = new AutoResetEvent[releasePaths.Count];
            
            int _h = 0;
            foreach (var item in releasePaths)
            {
                Console.WriteLine("In:_h={0}", _h);
                are[_h] = new AutoResetEvent(false);
                Thread thread = new Thread(() => item.SendFile("2012-9-11.zip", are[_h]));
                _h++;
  
                thread.Start();
            } 
            WaitHandle.WaitAll(are);
public bool SendFile(string from, AutoResetEvent autoRE = null)
        {
            try
            {
                if (lowPath.StartsWith("ftp://"))
                {
                    try
                    {
                        FTPclient ftpClient = new FTPclient(lowPath, User, Password);
                        return ftpClient.Upload(from, lowPath);
                    }
                    catch (Exception)
                    {
                        return false;
                    }
                }
                else
                {
                    if (!DstPath.EndsWith("\\"))
                    {
                        DstPath += "\\";
                    }
                    int times = 0;
                    while (times < 10)
                    {
                        try
                        {
                            File.Copy(from, DstPath + System.IO.Path.GetFileName(from), true);
                            return true;
                        }
                        catch (Exception e)
                        {
                            lock (ReleasePath._LockObj)
                            {
                                Log.WriteLog("Exception: " + e.Message);
                            }
                            Thread.Sleep(300000);
                        }
                        times++;
                    }
                    return false;
                }
            }
            finally
            {
                if (autoRE != null)
                {
                    autoRE.Set();
                }
            }
        }
Thread thread = new Thread(() => item.SendFile("2012-9-11.zip", are[_h]));
Thread thread = new Thread(() => item.SendFile("2012-9-11.zip", null));