如何使用Windows服务从文件夹到服务器获取txt文件 [英] How to take txt file from folder to server using windows service

查看:113
本文介绍了如何使用Windows服务从文件夹到服务器获取txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我需要将文本文件从源文件移动到目标文件,当我将文件复制到源文件时我需要消息请等待,复制后文件复制你移动目的地使用Windows服务。请帮帮我。



我的尝试:



 DirectoryInfo dir = new DirectoryInfo(@D:\ Vivek); 

FileInfo [] files = dir.GetFiles();

foreach(文件中的FileInfo文件)
{
if(file.Length> 0)
{
//你可以在这里删除文件你想要(目标文件)
if(File.Exists(@D:\ Vivek \ Moved\+ file.Name))
{
File.Delete(@ D:\ Vivek \ Moved \+ file.Name);
}

//然后将文件复制到这里
file.MoveTo(@D:\ Vivek \ Moved\+ file.Name);

}
}

解决方案

考虑在工作线程上复制,然后就可以了仍然更新GUI。



参见

.NET中的线程初学者指南:n的第1部分 [ ^ ]

使用工作线程 [ ^ ]

.NET和WinForms中的线程化攻击 [ ^ ]

Dear Friends,

I need move text file from source to destination and when coping file to source i need message "Please wait, file copying after copied you move to destination" using windows service. please help me.

What I have tried:

DirectoryInfo dir = new DirectoryInfo(@"D:\Vivek");

            FileInfo[] files = dir.GetFiles();

            foreach (FileInfo file in files)
            {                
                if (file.Length > 0)
                {                   
                        // you can delete file here if you want (destination file)
                        if (File.Exists(@"D:\Vivek\Moved\" + file.Name))
                        {
                            File.Delete(@"D:\Vivek\Moved\" + file.Name);
                        }

                        // then copy the file here
                        file.MoveTo(@"D:\Vivek\Moved\" + file.Name);
                    
                }
            }

解决方案

Consider doing the copy on a worker thread, then you can still update the GUI.

See
Beginners Guide to Threading in .NET: Part 1 of n[^]
Using Worker Threads[^]
Threading in .NET and WinForms[^]


这篇关于如何使用Windows服务从文件夹到服务器获取txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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