Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0 CSV
Hi Experts,
In my C# windows application.
for example i have two buttons(Export and Cancel).
If i hit export button it will perfrom the operation like exporting/writing some large data to .CSV file.
Its working fine.
While writing to the .CSV file, when i hit the cancel button writing file need to be stop and delete the file.
Please share with me your ideas.
Posted 20-Sep-12 19:43pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can Create BackgroundWorker which can be used to work in background and you can handle events to perform your desired work.
Check MSDN Article : Background Worker[^]
Hope it will work for you.
D-Kishore at 21-Sep-12 1:54am
Yes Amit,
Here i am using thread for export button.
When user hit the cancel button here i am aborting the thread. after aborting the thread i am deleting the file.while deleting the file i am getting the exception like 'The process cannot access the file 'D:\myCSVfile.csv' because it is being used by another process.'
Kindly give me an idea
@AmitGajjar at 21-Sep-12 1:55am
are you using Background worker or simple Thread ?
D-Kishore at 21-Sep-12 1:57am
using simple thread.
thrThreadExportProcess = new Thread(() => startExport(csvPath));
thrThreadExportProcess.IsBackground = true;
@AmitGajjar at 21-Sep-12 2:02am
Ok, Use thrThreadExportProjecss.Join() to waint for thread to abort. after that you need to write logic to delete the file.
D-Kishore at 21-Sep-12 2:08am
Thanks a lot,
It works fine
mine is 5+
@AmitGajjar at 21-Sep-12 2:09am
Thanks D-Kishore

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 345
2 CPallini 200
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,028
2 CPallini 4,700
3 George Jonsson 3,142
4 Gihan Liyanage 2,450

Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100