|
Clonning a partition is not an easy task, and by far an easy one to do with managed code.
If you want to do a full clone then your aim is to understand partition descriptors, file and folder descriptors and all the stuff that goes behind a file system when it acceses a partition. Why it is necessary to understand them, simple you can't just rely on the file system of an os and there are lots of existing partition types.
If you want just to copy all the files from a partition to another you must keep in mind that critical files opened by the operating system and/or applications are not readeable (nor writable) unless they are closed (or opened under special conditions).
ps: partition != hard drive
I have no smart signature yet...
|
|
|
|
|
You're not going to do it in managed code. In the simplest form you can do this, it requires that Windows isn't running since there will be plenty of areas of the disk that will be locked and unavailable to even be read.
I wrote an app to do this way back in 1991, written in C and running from a DOS boot floppy. I was duplicating hard drives for the mass production of "laptop" computers for Prudential Insurance. Every machine has a standard DOS/Windows/software load that had to be on about 450 machines.
For those keeping score, Ghost came out 2 years later in 1993. Yeah, there's my moment! ...had I only known there was a market...
|
|
|
|
|
I have a treeview where many treenodes belonging to different parent nodes may represent the same object, so if a user updates a text for such node, it should also trigger an update of text for all other nodes representing the same object. For instance if I have nodes representing school classes (math, english...) each class node has student nodes with student name as text, so numerous classes can contain the nodes with same student name. If I change students name under one parent, it should update it under the rest. I would assign the student object to nodes tag, but how would I trigger a text update?
thanks
|
|
|
|
|
There are a number of ways.
Ideally, the student class has a ToString or similar method that is used to format the text for the node.
Then you can enumerate the nodes, updating the text. You can probably make that quicker by checking to see if it's the updated record. And you should probably do that on a thread.
|
|
|
|
|
I do not have a collection of other nodes that need to be updated, so cannot enumerate. This is a form treenode, not web, so there is no updateOnDemand property. I was thinking of doing this on text update - calling tag object method that in turn calls treenode's method to update the text. this way, a single node text update would trigger text update for all nodes tagging the same object. Is there a better way?
|
|
|
|
|
xilefxilef wrote: I do not have a collection of other nodes
The tree has a collection of all the nodes -- enumerate them, updating as necessary.
You can use memory rather than CPU to maintain your own collections, but I'd start with the simple way first.
|
|
|
|
|
Right, it has all nodes, but this way I need to enumerate through all of them and find the ones I want to update. I was talking about an event that would trigger an update without having to enumerate through the whole tree. I would override TreeNode.Text property to point to tagged object's text property, but strings are immutable and if I change tagged object's text property, it would do nothing to nodes text.
|
|
|
|
|
That would be good if it can be done, but I don't know that it can (or can't) be done. I was thinking of having the student class have an OnChanged event (or something) that a specialized TreeNode could hook onto.
Failing that, you could have a class that associates a student with a bunch of nodes.
|
|
|
|
|
Yes, event triggered by tagged class is probably the best solution, but keeping a node list in tagged class is also good.
thanks.
|
|
|
|
|
xilefxilef wrote: is also good.
It's just more memory-intensive, I'd prefer to try the CPU-intensive solution and then decide whether or not it provides good performance
|
|
|
|
|
Hello, I'm beginner in C# and trying to make a GUI program. I'm making a program to play Sudoku, I've few classes, some functions and interfaces but problem is I can't get how should I update my GUI. I want a program that could update GUI for every action taken within class. Is it doable without touching functions in my classes just by inheriting the main form class ?? How could I do it and what is the best way of updating a GUI from a different class. Could I pass my user control directly to update GUI.
|
|
|
|
|
The normal way in a WinForms app would be to perform all the painting in a Paint handler, and calling Control.Invalidate() whenever said Control needs a repaint.
BTW: calling Control methods has to be performed on the main (aka GUI) thread.
I have a basic animation example here[^]; the principles are the same if you don't want an actual animation.
Out of curiosity, what is you Sudoku app going to do: generate puzzles, solve puzzles, act as a board game where the player solves the puzzle and the app checks, ...?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi guys... anyone know how to use the DataGrid from the WPF toolkit? I've looked it up in the MSDN but the examples they show don't seem to work.
I've got a filled DataSet object from a MySQL database and I want to display the contents in the DataGrid. The MSDN says I just have to use the DataContext property and set it to the DataSet but that's not working.
Anyone have any ideas?
|
|
|
|
|
You might want to post this question in the WPF forum instead.
|
|
|
|
|
hello,
i cant understand why the following code var ans = _textL.Skip(listBegin).Take(150);
doesnt work (the sublist 'ans' size is 0)
_textL.count = 155000
thanks
|
|
|
|
|
And what is the value of listBegin?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
Not sure what you're getting at here. I think the 2nd example doesn't even need or use
int? _someValThatNeedsSetting;
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Depending on the complexity of the calculation and the number of times the getter is called, I would expect option 1 to be the preferred choice. This is because after the first call there is no calculation to be performed and the test for nullability should take fewer cycles than the call to the calculation method and the actual calculation.
In option 2 the _someValThatNeedsSetting variable would not be needed, but each call would require a call to the calc routine and the actual calculation.
It's time for a new signature.
|
|
|
|
|
I expect example 1 (with the test) to always be at least as fast as example 2 (with extra method call), unless the method is very simple (yours is!) and conditions are such that the compiler can inline the code (I think that requires a "no debug" condition, say a release build).
However, I don't like nullables much, so I would opt for a separate boolean flag here. So that would be an example 1+
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi, still getting to know C# and recently stumbled upon a problem I'm not sure about.
I have two threads, each of them updating a WinForm's TextBox. I'm using the usual InvokeRequired:
if (this.OutputConsole.InvokeRequired)
{
this.OutputConsole.Invoke(
new OutputConsoleUpdater(delegate(string s) { this.OutputConsole.AppendText(s + "\r\n"); }),
text
);
}
else
{
this.OutputConsole.AppendText(text + "\r\n");
}
But bad things happened when I tried to add some sort of locking to that o. I just added a lock around the above mentioned code
lock(ConsoleLock)
{
}
A deadlock occured, the thread that actually needs the Invoke gets the lock ("user thread"), and tries to call Invoke, "delegating" the code to the thread that created the control ("original thread"). The original thread, though, wants to write something to the TextBox too, and is stuck waiting for the lock, currently held by the user thread, which in turn keeps waiting for the original thread to process the delegated call. So far, so good.
The question is: if I remove the lock, why does it still work okay... is the TextBox, in some way, thread-safe? Is it due to the way the Invoke call works (and if so, how does it work in the first place)? I don't really see how I could make it work using locks anyway (as long as I have to use the above mentioned paradigm), do you see how it could be done?
thanks for your time !
|
|
|
|
|
Why do you think a lock is necessary here? Lock is necessary when accessing finite resources such as a file where you need to ensure only one thread updates it a time. With the textbox you only need to use the Invoke method it you are trying to update it from a thread other than the UI thread.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Um, coming from C++, I would have thought calling a function from two different threads might cause some re-entrancy issues when working on a common resource (the TextBox's content they both try to update). I would have expected the output to be either interleaved ("AAAA" and "BBBB" resulting in "AABABBBA" for example) in the better case, or some variable corruption in the worse case.
|
|
|
|
|
Yes, the original code is thread-safe. This is how it works:
- thread 1 calls the method containing your snippet, I'll call it SetText();
- it detects invoke is required, launches a windows message to the GUI thread, and waits for it to return;
- the GUI thread now executes the same method SetText(), sees no invoke is required, sets the TextBox property, and returns;
- this causes thread 1, still waiting inside its SetText(), to continue.
Now everything the GUI thread does gets sequenced (well, not absolutely aacurate, but good enough here) through its event queue, so even if another thread (thread 2) were to call SetText, it would basically execute the same steps as listed above, and the common part, executed on the GUI thread, would be sequenced by the event queue.
So any number of SetText() calls will execute in the order they get called, without them interfering amongst themselves.
Adding a lock does not make it any safer; and as you discovered, if it covers the entire content of SetText(), it brings everything to a halt, as the basic concept of the construct is that SetText, when called on a thread other than the GUI thread, causes itself to be executed once more, on the GUI thread, which would be prevented by the very lock you added.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi, thanks for the answer... good to know about the queue
I think you confused the SetText (aka the snippet) thing though. Unless C# does something behind my back (not that I'd be surprised but I guess it would require the CLR to detect the caller of the Invoke method and recall it, and on top of that, it would render the delegate parameter useless), SetText doesn't get called again, so the deadlock is not due to the SetText method recursively calling itself in another thread (in fact, the deadlock only happened in certain cases and required a lot of tries to replicate in each of those cases).
In other words, "as the basic concept of the construct is that SetText, when called on a thread other than the GUI thread, causes itself to be executed once more, on the GUI thread" seems wrong to me Just going over it here so that I know I'm not mistaken...
|
|
|
|
|