|
How can I write my own binary file? Is it more efficient than the method I mention in the post (with the dataGridView)?
|
|
|
|
|
The binary Office files contain pointers within them so they are more akin to databases (from my limited guesswork).
Creating a binary file is neither here nor there - you will be the person who knows if you need to create a binary file.
You may find XML is a better format for saving data from a datagrid.
XML is a bit bloated but it is easy to read and with LINQ you can even query it directly.
If it is of any help to you in my 20 years of IT experience I have never come across any need to create, or access programatically, a binary file - that does not mean that you may not need to though.
As this is beyond my current knowledge I suggest you google and read up on binary files - then why not post an article on your findings.
Good luck.
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
GuyThiebaut wrote: You may find XML is a better format for saving data from a datagrid.
I'll second that.
GuyThiebaut wrote: I have never come across any need to create, or access programatically, a binary file
I've had to support systems that do.
|
|
|
|
|
PIEBALDconsult wrote: GuyThiebaut wrote:
I have never come across any need to create, or access programatically, a binary file
I've had to support systems that do. [Dead]
You have my condolences
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
To answer your questions:
1) In my other post I gave this answer (look up info about System.IO )
2) No, binary read/write in .NET hasn't been optimized by the MS crew as much as text files and XML files. The processing required to deserialize a binary file at times can lose the any speed advantage you'd gain.
Back in the day we has direct access to the system memory and could read/write it's contents to a file and .NET runs in a virtual machine where you don't have direct access to the system hardware. Otherwise your access to it is "managed" though the .NET virtual machine.
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
That Asian Guy wrote: a "binary format"
As in "one of an infinite variety of binary formats". Word uses one binary format, Excel uses another, etc. (and even that's simplified).
Even your example shows that simply saying "saving a regular text file" gives very little information on the format of the data: CSV, XML, and HTML are all "text files".
The difference between text and binary files (in essence) is that if I have a (one byte) numeric value 1 and store it in a text file, the actual value written out (after a ToString) is 49 (the ASCII code of the character '1'); but with a binary file I can write out the value 1 directly.
This can save space because saving the string "123" to a text file requires three bytes, whereas saving the numeric value 123 requires only one byte.
There are usually other differences as well, most notably the translation between NewLine and CarriageReturn/LineFeed, but those tend to be platform-specific.
|
|
|
|
|
Alright I see, thanks people!
|
|
|
|
|
I'm new to writing services and I'm having some trouble figuring out a way to write configuration settings so the service would be able to read it.
I decided to write a separate configuration application with its own namespace. I tried loading the setting by declaring and assigning a new instance of the settings from the other project. Problem is... it doesn't load from the other project, it loads a new instance of those settings for the current project (which makes sense, really -wouldn't want other applications accessing my settings).
My question is, how should I get past this security feature. Is there something built into the ApplicationSettingsBase type that I'm not aware of? Should I save to and load from a static config file? Should I use an INI instead?
Any thoughts would be appreciated.
|
|
|
|
|
I decided to serialize the object i was using to keep my configuration settings and save it to a static xml file. This seems like the simplest method to me.
To reiterate my original question:
Does anyone have any tips on the best practice for setting up a configuration tool for another application? I did some digging and can't quite find anything.
Although... an idea just struck me.
What if I call the config tool from the same executable that the service is run through? I'll have to try this out later since I've already got this working.
|
|
|
|
|
If I fire up a few threads and then want to stop execution in my main thread untill those threads are finished.
What is the most correct way to wait for those threads?
I've always been cheeting and use a dumb loop which checks some condition and then sleeps x ms if the condition was not met.
But I guess thats far from optimal.
(Although thats what I read that lock{}/monitor.tryenter does internally.)
pseudo sample of what I do:
void Foo()
{
perform some async tasks
wait untill all of them are done // whats the best way to achive this part?
return
}
|
|
|
|
|
|
I know how to use async callbacks.
But what I need is to block the execution just like in my sample:
foo()
{
start async tasks
wait for all threads //<-- that part
return processed result
}
|
|
|
|
|
You could call the Thread.Join[^] method on each thread you start, this will block the calling thread until all threads are finished.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
My standard model for multithreading (in a windows app) is to create a a wait form. You can put a progress bar or a label or whatever you want to use. For my threads I use the System.ComponentModel.BackgroundWorker . I'll briefely explain the basics.
My code will create the BackgroundWorker and set up the method it will need to run.
BackgroundWorker myWorker = new BackgroundWorker();
myWorker.DoWork += new DoWorkEventHandler(myWorker_DoWork);
The method passed in looks like this
private void myWorker_DoWork(object sender, DoWorkEventArgs e)
{
}
My WaitForm accepts the BackgroundWorker as a parameter to the constructor.
My WaitForm accepts the background worker as an input parameter. You can set up the worker in the WaitForm to handle progress changed events to modify the message and even a progress bar in the wait form. Also, you will want to set the RunWorkerCompleted event and make it close the WaitForm.
Then, append this below the first block of code.
WaitForm waiting = new WaitForm(myWorker);
waiting.ShowDialog();
By using ShowDialog you are forcing the current thread to wait until the dialog is done. Because the worker is working the dialog won't close until myWorker_DoWork completes.
Also, this is another good approach which I have used on a few applications.
Broken Bokken
You can't carry out a ninja-style assasination dressed as an astronaut. It's the luminous fabric; too visible. - Tripod
The story of your fighting is a poem of two words: YOU SUCK.
|
|
|
|
|
This is not what I want to do.
Im starting up some slow remote task async and I need the result from all of them before the method can return its result.
So Im not asking how to show forms or anything, just whats the correct way to wait for the result of all of them while still inside the method that fired up the async tasks.
|
|
|
|
|
If you block execution of the calling method right after you make the thread. My question to you is: Why did you make it another thread?
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
Im firing up multiple async tasks, so its not just one thread.
its multiple remote services that are called async
and I need to wait for all of them to finish so I can pick up the result and process it and then finally return the processed result from my method.
|
|
|
|
|
Greeeg's answer of Join is what I would suggest you look into.
The Join method basically waits until other threads are finished before resuming executin on the current thread
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
If you go with a ISyncResult object with a delegate called through begineinvoke then you can use waitone and do the same thing...
There are multiple ways to do what the OP asked, which method to use is mostly based off of the context of what you are doing.
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
I have three threads that are trying to write events to a single event log -- with each thread being a separate source. Each thread creates an instance of the EventLog and uses eventLog.WriteLine() to post the event. In initialization each thread checks to see if its' source name is registered to the log. If it not, it registers itself. Then each thread creates an instance of the eventlog passing the logname and source name, after which a success message is posted to the EventLog.
The first thread establishes itself and its' events are getting logged without problems, but the other two threads are not getting their events written.
Any help would be appreciated.
|
|
|
|
|
At what point is it failing?
1.
LongRange.Shooter wrote: each thread checks to see if its' source name is registered to the log
2.
LongRange.Shooter wrote: If it not, it registers itself
3.
LongRange.Shooter wrote: a success message is posted to the EventLog
4.
LongRange.Shooter wrote: thread creates an instance of the eventlog passing the logname and source name
Working through the above list should help solve your problem.
You obviously have it coded correctly in the first thread - have you tried altering/controlling the order of these threads to check if the code is functional in the other two - i.e make the second tread do it's stuff first?
Just seen the thread below! It looks like you might have found the root of the problem.
Dave
modified on Wednesday, May 7, 2008 3:03 PM
|
|
|
|
|
I am trying to automate Excel from within my C# application, and am receiving the above error.
I have added a reference in my project to the Microsoft Excel 12.0 object library which adds the Microsoft.Office.Core and Microsoft.Office.Interop.Excel namespaces (but strangely not the the Excel namespace - this is is only added when I add a reference to the Microsoft Excel 5.0 object library).
I have downloaded the latest Primary Interop Assemblies (PIA) for Microsoft Office from the MS download site, and added the following code to my program as well:
using Excel;
I still get the error. I have run out of ideas!!
Any help much appreciated.
|
|
|
|
|
Instead of "using Excel;" you should have "Microsoft.Office.Interop.Excel;" or you can create an aliases for that like this: "using ExcelInterop = Microsoft.Office.Interop.Excel;"
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
"Cannot create an instance of the abstract class or interface 'Excel.Application"
You cannot create instances of abstract classes or interfaces... Also, I don't see how your question has anything to do with this title.
Excel is not the namespace, use Microsoft.Office.Interop.Excel.
Cheers,
|
|
|
|
|
Please me Remoting concept of dot net in detail
---
Regards
ilango gandhi
' Knowledge can only be got in one way, the way of experience; there is no other way to know.'
|
|
|
|