ile kullanılıyor. Sadece yeni oluşturulan dosyalar için belirli bir klasörü izleyecek ve liste kutusunda listeleyecek bir uygulama oluşturdum, şimdi yapmak istediğim, dosyayı her defasında algılayacak Uygulama bunu okuyacak ve liste kutusundaki metni gösterecek, neredeyse var çünkü bazen 2 veya 3,4,5,6 vb. dosyaları tespit ettiğinde bazen tamam ama bazen "hata" işlemi "dosyaya erişemiyor" C: \ Users \ PHWS13 \ Desktop \ 7.request.xml 'çünkü başka bir işlem tarafından kullanılıyor.Dosya başka bir işlem tarafından FileSystemWatcher ve Task
Bunu nasıl düzeltebilirim? İşte benim kodum:
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
if (!listBox1.Items.Contains(e.FullPath))
{
//add path
listBox1.Items.Add(e.FullPath + "" + DateTime.Now.ToString());
//get the path
path = e.FullPath;
//start task
startTask();
}
}
private void startTask()
{
//start task
Task t = Task.Factory.StartNew(runThis);
}
private void runThis()
{
//get the path
string get_the_path = path;
XDocument doc = XDocument.Load(get_the_path);
var transac = from r in doc.Descendants("Transaction")
select new {
InvoiceNumber = r.Element("InvoiceNumber").Value,
};
listBox2.Invoke((MethodInvoker)delegate() {
foreach(var r in transac){
listBox2.Items.Add(r.ToString());
}
});
hala aynı, denedi! :( – GrayFullBuster
hey, ben sadece bunu ekledim "FileShare.ReadWrite" – GrayFullBuster
Çalışmıyor Not Aynı şeyi yaptım –