|
jain.ashish21 wrote: For this to happen in current scenario the client will have to have the excel object library too in the bin folder.
Is that such a big deal?
|
|
|
|
|
Dear sirs:
I wrote program that performs one resource-intensive operation. This operation is to convert PDF into a text file. I decided to spin-off this single operation on a threading delegate as shown below:
Class Pdf()
{
public delegate string PdfIsbn();
string ISearch.Isbn( string sFileName )
{
m_sFileName = sFileName;
PdfIsbn pdfIsbn = new PdfIsbn( GetIsbn );
IAsyncResult iasResult = pdfIsbn.BeginInvoke( new AsyncCallback( IsbnComplete ) , "Isbn is complete" );
/**********************************
******** Regular Processing *******
**********************************/
// It only works if this code is un-commented.
while (!iasResult.IsCompleted)
{
Console.WriteLine("Please wait...");
//return m_sIsbn;
}
return m_sIsbn;
}
private void IsbnComplete( IAsyncResult iasResult )
{
AsyncResult ar = ( AsyncResult )iasResult;
PdfIsbn pdfIsbn = ( PdfIsbn )ar.AsyncDelegate;
m_sIsbn = pdfIsbn.EndInvoke( iasResult );
Constant.g_iThreadCount -= 1;
}
string GetIsbn()
{
Constant.g_iThreadCount += 1; // Increment thread-counter.
Console.WriteLine( "Pdf version of search implemented" );
Thread.Sleep(5000);
dtSearch dtSrch = new dtSearch( m_sFileName ); // Pass-in filename only.
regEx = new RegEx( "Isbn" ); // Search for a regular expression that fits the "ISBN"-type.
SearchIsbn( regEx , dtSrch.ResultText );
return m_sIsbn = regEx.RegExResult; // Get the ISBN.
}
}
The Main program is a windows form with a DataGridView. The main loop cycles through subfolders; each one containing a PDF.
do
{
try
{
file.GetDirectory(); // gets a book inside a directory, performs search etc.
// If a valid ISBN is found it will show up here.
if (file.SearchItem != "")
{
newBooks.AddBook(new Book(true, file.FileName, file.SearchItem));
}
}
catch (Exception ex)
{
file.LogError(ex, ex.Message.ToString());
}
} while ( file.SubFolder != "sub-folder iteration completed." ) ;
bindingSourceEbookCollection.DataSource = newBooks;
dataGridViewEbookCollection.DataSource = bindingSourceEbookCollection;
dataGridViewEbookCollection.AutoGenerateColumns = true;
I have tried to make the grid "aware" of all of the new book-entries being made inside the collection to which it is bound; to no avail.
I tried using a global "Thread Counter" so that the loop would keep executing until all the threads have been processed; and putting the "grid-binding" code inside the loop with the intent being that it would be "refreshed" with the new book-data.
The way the code is written now, the books show up but only after they have ALL been processed and the grid is blank until the whole process (all books) is completed.
The idea behind "encapsulating" the single, resource-intensive process inside a thread was to show the status of "processing... " inside the data grid for each book that was spun-off on a thread.
Any help is appreciated.
Many thanks,
R. Hyland
|
|
|
|
|
Maybe I am missing something here, but it seems like you should be updating your grid when the async event comes back:
private void IsbnComplete( IAsyncResult iasResult )
{
Then you need to do something like Application.DoEvents for your grid to repaint.
Hope that helps.
Ben
|
|
|
|
|
Thanks, I finally got it to work per your advice.
-- modified at 15:19 Thursday 24th May, 2007
|
|
|
|
|
I have old code written at VS 2003 which uses VS6/MFC.
When I try to run it at .Net 2.0 frame work, I got error ( I think a tone of MFC dll ).
Do you konw any links to solve it?
thanks!
|
|
|
|
|
Reli A. wrote: I have old code written at VS 2003 which uses VS6/MFC.
OK, so which is it, MFC7.1, or MFC6 ?
Reli A. wrote: When I try to run it at .Net 2.0 frame work, I got error ( I think a tone of MFC dll ).
You mean it blows up when it runs, or when it compiles ? If it builds in VS2005, it will link to the VS2005 dlls, I'd have thought. What errors are you getting ?
This question has nothing to do with the .NET framework, if you're talking about a C++/MFC app, so I'd ask it in the C++ forum.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hellow to all
i am installing an app that i had wrote in win98 , that have all the framework updates ..
and every time i run the program i get this error
Application has generated an exception that could not be handled
process id=0xfff87f77 (-491657) , thread id=0xfff96927 (-431833)
|
|
|
|
|
So what did you do in your application that Windows 98 doesn't support? Did you EnableVisualStyles maybe? Or something else?
|
|
|
|
|
|
Hello!
Tell me please, how can I load pictures into WebBrowser control from the resources?
|
|
|
|
|
you can't directly - your web browser can only read HTML, with img tags which point to images on your hard drive, or on the network/internet.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Am I correct in assuming that if I have VS.NET 2005 installed and then put on the latest 3.0framework that I can still do projects that are NOT dependent on the V3.0 framework? I don't want to have to convert all my 2.0 projects over and I am not all that ready to start playing with all the cool V3.0 stuff just yet, I only want to start playing with the SCSF and the last build seems to require the update framework.
|
|
|
|
|
yes.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks. I am not quite ready to delve into WPF just yet.
|
|
|
|
|
3.0 just adds to 2.0, in the same way that you can still use untyped collections in 2.0, but the new stuff is there, and better.
Yeah, I wish I had time for WPF, but I still don't, much.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hey i'm creating a xaml browser application and I want to bind a database with a listbox in the interface ..does anyone has reference or an article that explains that??
I found an article but it's for windows apllications
|
|
|
|
|
It shouldn't really be much different than from windows apps, have you resolved this?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Hello,
This relates to my question yesterday, but this question is far more specific so I figured it best to start a new thread regarding it.
I am currently trying to design a method that will detect whether or not a folder is being actively copied to once it is detected by my application. For my program to function correctly, any detected folders in the target directory MUST be finished being copied to before my program can pick them up for processing. However, no matter what I try, my program tries to grab the folders and move them for processing before the copy is actually finished.
So far I've tried checking the LastWriteTime and LastAccessTime of the directory via the DirectoryInfo class. For some reason, these properties would state that the last write and access times were x seconds ago, even when the files were not completely done copying.
I thought this might be caused by files being written to subfolders inside the folder I was checking (which I'm assuming are not checked in reference to that particular top folder), so on a suggestion from Christian Graus, I tried a recursive script that would get the size of all files and folders inside the target folder and return that value. My program would use this method to first get the size of the folder, sleep the thread for a second, then recheck the value. If the values matched, the folder would be processed. If they didn't match, the folder was passed over and checked on the next cycle. However, even though the files were still not done copying (the file copy progress box was still showing), the cumulative directory size would be reported as the same on both checks and it would pick up the folder early again. I also checked the reported size value against the actual size of the folder (though the properties window in Windows) and the reported size matched the actual directory size, even though my program got that value while the files were still actively copying (once again, the file copy progress dialog was still visible and progressing).
So I'm really at a loss here. Does anyone know of a method to check a folder's activity and report whether files are still actually being copied to it? I've posted some of the relevant snippets, in case I just boffed my code and didn't realize it.
Thanks in advance for any assistance.
Code for getting folder size:
<br />
public static class Utility<br />
{<br />
public static int GetSize(DirectoryInfo dir)<br />
{<br />
int size = 0;<br />
foreach (FileInfo f in dir.GetFiles())<br />
{<br />
size += (int)f.Length;<br />
}<br />
foreach (DirectoryInfo d in dir.GetDirectories())<br />
{<br />
size += GetSize(d);<br />
}<br />
return size;<br />
}<br />
}<br />
Code for scraping the target directory and checking whether a folder is done being copied to or not (code relevant to this issue is bolded):
<br />
void RunAsyncScrape(object sender, DoWorkEventArgs e)<br />
{<br />
DirectoryInfo[] studies;<br />
try<br />
{<br />
studies = new DirectoryInfo(targetdir).GetDirectories();<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show("Could not scrape the target directory\nReason: " + ex.Message, "File Scraping Error");<br />
}<br />
<br />
if (studies.Length > 0)<br />
{<br />
ArrayList orders = new ArrayList();<br />
foreach (DirectoryInfo dir in studies)<br />
{<br />
int size = Utility.GetSize(dir);<br />
Thread.Sleep(1000);<br />
int sizeb = Utility.GetSize(dir);<br />
if (size == sizeb)<br />
{<br />
orders.Add(dir)<br />
}<br />
}<br />
if (orders.Count > 0)<br />
e.Result = orders;<br />
}<br />
}<br />
|
|
|
|
|
Christoff915 wrote: So far I've tried checking the LastWriteTime and LastAccessTime of the directory via the DirectoryInfo class. For some reason, these properties would state that the last write and access times were x seconds ago, even when the files were not completely done copying.
This is true. The reason is because NTFS only updates those properties every once in while. It does NOT do it on-the-fly as the file is being written to. So, the file WAS written to at that time. It doesn't mean that the file write has stopped yet.
Christoff915 wrote: I thought this might be caused by files being written to subfolders inside the folder I was checking (which I'm assuming are not checked in reference to that particular top folder), so on a suggestion from Christian Graus, I tried a recursive script that would get the size of all files and folders inside the target folder and return that value. My program would use this method to first get the size of the folder, sleep the thread for a second, then recheck the value. If the values matched, the folder would be processed. If they didn't match, the folder was passed over and checked on the next cycle. However, even though the files were still not done copying (the file copy progress box was still showing), the cumulative directory size would be reported as the same on both checks and it would pick up the folder early again. I also checked the reported size value against the actual size of the folder (though the properties window in Windows) and the reported size matched the actual directory size, even though my program got that value while the files were still actively copying (once again, the file copy progress dialog was still visible and progressing).
Again, you're checking this information faster than NTFS updates it! NTFS is LAZY. You cannot depend on the properties to tell you when the folder is finished.
You can't check this every second to see if it's done. You're simply not going to know unless the application that is writing the data tells you. Somehow, I doubt that it has any such capability.
Since the app can't tell you when it's done, you're only semi-reliable method is to check for the existance of the folder and get it's total size, about once every 15 seconds, and KEEP DOING THIS! If the size doesn't change for, say, the last 3 passes, then you can assume the app is done writing to the folder.
Note, I said "assume". Because of system failures or loads, or whatnot, there is no absolutely 100% reliable method of knowing when the other app is done. THe only way that's going to happen is if the other app tells you it's done.
|
|
|
|
|
Dave, thanks for the quick reply.
That is a disappointment, although the information you provided cleared up a lot of the confusion I have over this issue.
Back to the drawing board, I guess...
|
|
|
|
|
Since the application is trying to write the file to a folder. You can check to see if you can get exclusive access to the file. If you can then that file must be done. Now like it has been said before the process might have failed etc, but if you can get exclusive rights to the file, then nobody else can touch the file. If you in control of the other app, you would want to do the same thing. Look at the FileInfo class
FileInfo fi = new FileInfo("temp.txt");
FileStream fs = fi.Open( FileMode.Open, FileAccess.ReadWrite, FileShare.None );
fs.Close();
Hope that helps.
Ben
|
|
|
|
|
That will work for that one particular file, but the app in question writes a bunch of files and folders inside the folder he's talking about. Managing watching all those files would be pretty chaotic.
|
|
|
|
|
Well, I figured he is already looping through all the files with is FileInfo loop. I figured it isn't much different then waiting 45 seconds and checking again to see if the size has changed. Anyway, it is the only way I know of, that ensures that the file is not still being written. That is usually the bigger issue. You don't want to try and process a file that is still writing to the folder you are looking at.
Ben
|
|
|
|
|
I'll look into your suggestion, Ben...thanks for the advice.
|
|
|
|
|
But it doesn't work if the application is writing to several files simultaneously or writing to the files intermittantly. Open the file, write, close, ..., rinse and repeat. Logging libraries do this frequently.
I know the technique you're talking about. I've figured out, the hard way, that it doesn't work all the time.
|
|
|
|
|