|
Did you try my second suggestion to do the File.Move WITHOUT the File.Delete ?
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
Yeah I did. I got the same exception. After tracing through it with the debugger the exception is thrown by File.Move(). I just don't know why. Is it a problem that I'm trying to rename my file to something that doesn't exist ?
|
|
|
|
|
No, you would get an exception if the file DID exist, as the method documentation states rather clearly.
It's possible it's not you using the file, either. The exception message states that the file is in use by another process. That could be use, or it could be another process. Make sure nothing else is using the file.
I've never had any problems deleting and moving files in two fell, sequential swoops. Some process - yours or not - is also using the file.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Here's the real kicker; the file does not exist. MyFile.bak does not exist on the hard drive so no other process can access it (I've also verified this by using SysInternal's handle program see what process is using what file and MyFile.bak was not in the list as expected).
|
|
|
|
|
The problem may also be that your SOURCE file is in use, not the destination. If you app has just written the .XML file, make sure that it was .Flush ed, .Close ed, and then the FileStream object .Dispose ed. This will release the unmanaged file handle in use by the FileStream object and release your file so you can rename it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I've been testing this problem and I came to the conclusion that it is specific to my machine only. When the code executes on someone else's machine it works fine. Thanks for all who replied trying to help me fix this problem.
|
|
|
|
|
When my app starts up it needs to spend a few seconds getting data from a database, and structuring tables etc. The user needs to know something is going on while this happens so I made a simple form that gives some feedback e.g."xxx is now loading".
Trouble is, the app is so busy loading the data that it never gets the chance to write the text in the form. The title is there, but little else (until the data has finished loading, when the form is not required any more anyway!) - just empty 'holes' which let the underlying screen show through.
There must be a simple solution to this but it eludes me.
|
|
|
|
|
What is required here is to have the main form perform the tasks while another form on another thread is processing the display. While it sounds complex, we have an article here[^] that will implement everything for you. I like this screen because of the predictive nature of the status bar. The only item I don't like is that it shows no progress the first time it is run unless you prepopulate the registry.
If you'd prefer other approaches, do a search from the home page for articles on Splash Screen.
|
|
|
|
|
Thanks 'Condor', this is a bit top-heavy in terms of code size (compared with what I was expecting!) but I have to admit the result is very nice. I'll use it.
|
|
|
|
|
You're welcome.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
I have a couple of questions about list box scrolling:
1. How you handle scroll events?
2. How do you get and set scroll positions?
Gary Kirkham
A working Program is one that has only unobserved bugs
He is no fool who gives what he cannot keep to gain what he cannot lose. - Jim Elliot
Who you are in Christ
|
|
|
|
|
Extend the class, override WndProc , and handle WM_HSCROLL (0x0114) and WM_VSCROLL (0x0115). I suggest defining two events and their virtual handlers (VScroll event fired by OnVScroll handler, and HScroll event fired by OnHScroll - the recommended way of defining events) and fire those along with any data you want in your WndProc override.
To set the position, you P/Invoke SendMessage and send those messages to your control's HWND (window handle, exposed by the Handle property). Note that when setting the position, you must also update the scrollbar position information by P/Invoking SetScrollInfo . Why and what you should pass is documented on MSDN[^] if you lookup WM_VSCROLL .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
When I try to make and test it in server explorer, this error message has shown:
Test connection failed because of an error in initializing provider. Cannot start your application.
The workgroup information file is missing or opened exclusively by another user.
Database was closed.
|
|
|
|
|
If you read the documentation for Access, you'd see that a workgroup file is an .mdw file (IIRC, it's been a while). There is a system default installed in the installation directory for Access, but if a particular .mdb file (Jet Database) uses unique credentials, it will have a different .mdw file (typically in the same directory). I don't remember what the connection string property is called (and those Access docs will tell you), but you must include that property and the fully-qualified path to the .mdw file, as well as credentials (User ID and Password) that are defined in that .mdw file in order to access the .mdb database.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
i'm trying to simulate what ping.exe does and send ICMP packets to a host. how can i do this in .net?
|
|
|
|
|
|
You could make your own using raw sockets and the ICMP protocal. But you don't have to becaue there is already a class to do it for you.
Icmp Class[^]
/\ |_ E X E GG
|
|
|
|
|
like others have suggested, u can use RawSockets and ICMP protocol type, or use an existing class like the one eggie5 has suggested.
Be aware that not all machines respond to ICMP echo request (which is what PING uses), and many firewalls might treat lots of ICMP echo request as an attack. The question is what are you trying to simulate? if you're in control of the host, have you considered using UDP?
|
|
|
|
|
Hi,
can anyone help me converting vb.net code given below into c#. I tried some converting tools but it will put the same code in c# and will give reference to Microsoft.VisualBasic.Compatibility, but i don't want that. i want the c# code for this method without using the reference to Microsoft.VisualBasic.Compatibility, also, if i have .dll project, how do i convert the .dll executable at the same time.. i appreciate ur help. Thanks...
vb.net code
-------------
Private Function GetSingleProperty(ByRef sElementName As String) As String
Dim vValues As Object
vValues = g_pPropSet.GetProperty(sElementName)
If IsNothing(vValues) Then
GetSingleProperty = ""
ElseIf VarType(vValues(LBound(vValues))) <> VariantType.String Then
GetSingleProperty = ""
Else
GetSingleProperty = vValues(LBound(vValues))
End If
End Function
vijju
|
|
|
|
|
You've already asked this question not more than an hour ago - be patient. See my reply, because you seem to be missing a key feature of the .NET Framework - the fact that it doesn't matter in what language the source was written because the assemblies all contain IL (unless they're mixed mode, which currently only MC++ supports (from the Microsoft camp)).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
thanks for replying. actually i am not very good at vb, but i am a little comfortable programming with c#. that is one reason i wanted to convert that code into c#. also, i wanted to know more about coupling and de-coupling, if i want to run my .dll project (which is going to be plug-in) as an executable at the same time. if you suggest any examples or material to follow-up the understand the architecture design, that will be GREAT. and also i didn't knew that my question was posted more than one time, and sorry about that..
Thanks
vijju
|
|
|
|
|
Coupling and decoupling has nothing to do with how code is executed - it has to do with how code is referenced.
Knowing the C# language doesn't mean you know .NET. If you want to learn more, I suggest you read the SDK, which should be installed on your machine (it is installed by default with VS.NET, but can be installed separately) and available online at http://msdn.microsoft.com/library/en-us/dnanchor/html/netfxanchor.asp[^]. Understanding at least the basic concepts of the CLR (like what assemblies are) is important.
Since you didn't tell me what g_pPropSet is defined as, I can only assume it's defined in the Microsoft.VisualBasic.Compatibility assembly. As I mentioned before - converting the code isn't a good idea, especially if you're new to .NET; you'll never learn anything that way. So, just converting the code to C# won't get rid of the assembly dependency - you'll have to rewrite it to use a similar class. Judging by what you seem to be trying to do, a suitable class might be the StringDictionary as I mentioned in my other reply.
If you want to know more about architecting .NET solutions, visit http://msdn.microsoft.com/patterns[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Besides, do you maybe want to put this in context? What are you trying to do? Extract a value from a collection? If all you did was convert from one language to another, you're constrained by what the rest of the code did.
Now, if you convert the concept, you could use many types to do this. For example, you could use a Hashtable or StringDictionary (or several other things in the BCL) to store string key/value pairs and refer to them by name:
StringDictionary dict = new StringDictionary();
dict["One"] = "Apple";
dict["Two"] = "Orange";
dict["Three"] = "Banana";
Console.WriteLine(dict["Two"]); When moving from one application framework to another, don't just convert your code. Advancements are made with newer frameworks. If all you're doing is porting your code just to run on the .NET Framework, you're doing a very stupid thing (any article by a decent author will tell you as much) - if it works, don't change it. If you have to change it to add new functionality later and to be maintainable by less-than-knowledge programmers, then change it in steps.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My VB is a bit rusty but I think this is your answer.
private string GetSingleProperty(string elementName)
{
object Values = g_pPropSet.GetProperty(elementName);
if (Values == null)
return String.Empty;
if (Values.GetType() != typeof(String))
return String.Empty;
return (string)Values;
}
|
|
|
|