|
So it seems that there is some time needed until the handle is actually released after you call Close on the stream.
|
|
|
|
|
so what can be the solution for this.....give me the solution....please
|
|
|
|
|
There is probably a better method by checking if the file is available but it's not something I've done so I'm not sure.
A quick solution maybe to insert a System.Threading.Thread.Sleep(i); where i = the number of miliseconds delay you need to put in for the file to be released.
Dave
|
|
|
|
|
you should use a timer, that will be enabled by your code, then in timer_tick event, first disable the timer then delete that file
i sure this will work
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hi,
if you want write or delete access (anything other than read access) to a file
that just got created (by yourself or someone else, does not matter),
chances are you will find the file is being accessed by some other process,
and your access is not granted.
The other process very likely is some server code that is there to assist you
somehow. Candidates are:
- anti-virus software (Norton, McAfee, whatever)
- indexing software (Google Desktop, MS Office, whatever)
The common thing is these packages are looking all the time for new files, so
they can inspect them.
Microsoft is aware of the consequences; Windows Explorer will try rename and
delete attempts up to five times (with one-second interval), and only reports
failure if the action continues to fail for that time.
The solution:
1. either use a different file name
2. or remove all background reader candidates (bad idea)
3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer
for this)
PS: while debugging and single-stepping, your code runs more slowly and is less
likely to be affected by the above...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi Neetu Maheshwari
i have answered this question fo this question last weekin code project fourms. please search like this "read a file with IO"
thanks
|
|
|
|
|
Hi friends ..
I am facing problem related to tabindex(focus) settings. Whenever I run the project, Initially focus goes to IE's address bar, but tab is
not set for that, how to avoid the focus not to go to address bar.
thanking you in advance ...
|
|
|
|
|
I must have posted this same line of code at least 3 times in the last week...
To set focus on any control on your form, use:
this.ActiveControl= myControl;
Do this at the end of your initialisation of your form to make sure the app is focused on where you want.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Hello friend
thank you for your reply ... but I want tab not to go in any case
to the IE's address bar ... means I want to block address focus..
waiting for reply
thank you ...
|
|
|
|
|
Aha, I believe you wish to set the "TabStop" property to true.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Assume I have two classes like this.
class Vehicle
{
public string Name
{
get { return name;}
}
}
class Bike : Vehicle
{
}
class Car : Vehicle
{
} I have a factory class like
class VehicleFactory
{
public static Vehicle CreateVehicle()
{
return new Car();
}
} Here the "Car " instance is down casted into "Vehicle " instance. Is this performance costly ? Or an approach with interfaces like the below one is better ?
interface IVehicle
{
void Name
{
get;
}
}
class Vehicle
{
public string Name{ get { return name;} }
}
class Bike : Vehicle , IVehicle
{
}
class Car : Vehicle , IVehicle
{
} and the factory returns IVehicle instance.
class VehicleFactory
{
public static IVehicle CreateVehicle()
{
return new Car() as IVehicle;
}
} Which one do you suggest ?
|
|
|
|
|
N a v a n e e t h wrote: Here the "Car" instance is down casted into "Vehicle" instance. Is this performance costly ?
No.
N a v a n e e t h wrote: Or an approach with interfaces like the below one is better ?
It depends on what you are ultimately trying to achieve. However, you may want to make Vehicle implement the IVehicle interface rather than Car or Bike as the Vehicle base class is what is actually implementing the interface.
|
|
|
|
|
Colin Angus Mackay wrote: However, you may want to make Vehicle implement the IVehicle interface rather than Car or Bike as the Vehicle base class is what is actually implementing the interface.
Thanks Colin. I also had doubt about this. Let me change it and try. Thanks again.
|
|
|
|
|
IMO, without pulling numbers out my arse:
Casting reference objects is extremely cheap.
You dont have to worry about that kind of things, up and downcasts will never ever be close to other performance issues in an application.
Eg, db connections, db queries, tcpip connections, rendering html and all that kind of stuff.
Premature optimizations are bad.
You will end up spending time and resources on things that doesnt matter.
So rule of thumb, if there is a Db or Webserver involved, you can do pretty wild stuff w/o running into performance issues since the overhead of DB calls / html rendering / connections is so huge that they overshadow the performance of slow'ish code..
Just my 2 cents.
|
|
|
|
|
Roger Alsing wrote: Premature optimizations are bad.
Thanks. I will take care this.
|
|
|
|
|
As you've had two excellent answers on the performance side, I'm going to turn this question on its head. Rather than looking at which is more performant, take a look at which is easier to develop and test.
Suppose that you want to create a more complex application and you are going to use TDD (Test Driven Development) to write it, it's easier to write and test an application that uses interfaces because you can quickly create Mock Objects that conform to the interface and test the main code in isolation.
Also, have a read up on Inversion of Control (IoC) and get an understanding of how that all hangs together. Philip Laureano has an excellent series of articles here on CP, one of which deals with an IoC container that he wrote.
|
|
|
|
|
Pete O'Hanlon wrote: Also, have a read up on Inversion of Control (IoC) and get an understanding of how that all hangs togethe
Thanks pete. Is this[^] the article you are talking about ?
|
|
|
|
|
No. I was thinking of this[^] one.
|
|
|
|
|
N a v a n e e t h wrote: class Vehicle
Why isn't the class abstract?
Here the "Car" instance is down casted into "Vehicle" instance. Is this performance costly ?
Doesn't cost a thing. The down cast is completely safe, so there is no code generated to handle it.
Or an approach with interfaces like the below one is better ?
You only have a use for the interface if you have a need to make a completely different implementation of the vehicle members for any class. If all vehicles will inherit from the Vehicle class anyway, the interface is superflous.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: Why isn't the class abstract?
Yes, I forgot that.
Guffa wrote: You only have a use for the interface if you have a need to make a completely different implementation of the vehicle members for any class.
This is clear Guffa. Thanks
|
|
|
|
|
The compiler knows at compile time that Car is derived from Vehicle, and the runtime allows a reference to a derived class to be stored in a reference to its base class. Compiling with optimizations on and debugging off (a release build) gives the following code:
.method public hidebysig static class Vehicle CreateVehicle() cil managed
{
.maxstack 8
L_0000: newobj instance void Car::.ctor()
L_0005: ret
} Note no cast instructions at all. All it's done is create a new Car and return it.
Going the other way:
public static Car ConvertToCar( Vehicle v )
{
return (Car) v;
}
.method public hidebysig static class Car ConvertToCar(class Vehicle v) cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: castclass Car
L_0006: ret
} This time the code can't know at compile time that the parameter v passed into ConvertToCar is actually a Car object, not a Bike or anything else deriving from Vehicle , so it generates a castclass instruction. This instruction checks that the actual type is either a Car or something deriving from Car , if so it modifies the reference as necessary (actually nothing needs to be done, the vtable pointer is always fine for base to derived conversions). If not it throws an InvalidCastException .
If you wanted to get a null reference instead you should use the as instruction - this is better if you're not certain that it's the right class. Adding two more methods:
public static Car TryConvertToCar( Vehicle v )
{
return v as Car;
}
public static bool IsCar( Vehicle v )
{
return v is Car;
}
.method public hidebysig static class Car TryConvertToCar(class Vehicle v) cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: isinst Car
L_0006: ret
}
.method public hidebysig static bool IsCar(class Vehicle v) cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: isinst Car
L_0006: ldnull
L_0007: cgt.un
L_0009: ret
} Note that using 'is' gives the effective equivalent code to:
public static bool IsCar( Vehicle v )
{
Car c = v as Car;
return c != null;
} Therefore I prefer using 'as' in all cases, because in almost all circumstances I want to manipulate the object as a Car rather than just find out if it is.
As a design question, I'd use a type field rather than inheritance unless I had a reason to use the polymorphism available through inheritance - one or more virtual functions with different behaviour in different classes in the hierarchy. It's simpler to understand and generally produces less indirection and less metadata.
(Code compiled by dropping into a .cs file and running csc /t:library /o+ /debug- vehicles.cs , and decompiled into IL with Reflector[^].)
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
That's great. There is a 5 for you . Thanks
|
|
|
|
|
Hi, I wounder if there is any way to have a cell in a DataGridView to show both a checkbox and text. Or is it possible to have a following text after the checkbox with the DataGridViewCheckBoxCell as with an ordinary win form checkbox?
|
|
|
|
|
Hi akkram
i think u can't directlly.
but you can create custom datagrid view from the base gridw view.
if you want to get sample source code from the Apress.com
thanks
|
|
|
|
|
Hi,
Ive written a small app which runs in the system tray and runs calls from a web service on a timer much like a windows service. I'm using C# Express so i had to write this as a windows application.
Everything is working great.
Only problem is that users are not allowed to exit this application.
Only way to kill the app is by killing the process in task manager.
Anyway if the user tries to shutdown his PC it just doesn't shutdown until the process of the app has been killed.
Anyone have a reason as why this is happening?
Thanks
|
|
|
|