|
Hey all,
I came across one unusual behavior of Directory.Exists() method when I was testing user path input, I was trying with different inputs just to test the existence of the directory on my local drive. For negative test cases I provided the existing directory path and put two ".." at the end of directory path
e.g.
lets say I have "C:\CurrentDir" on my local drive
when I check the existence of directory using
bool isDirExist = Directory.Exists(@"C:\CurrentDir..");//".." are appended
surprisingly isDirExist is true
when I try to access file contained in this directory it throws error......
it does not throw exception if I append only one "." [for @"C:\CurrentDir." +AnyFileName]
Is this is bug in Directory.Exists method or anything else is happening behind the screen at OS level??
|
|
|
|
|
SaveTigers wrote: surprisingly isDirExist is true
Directory.Exists is working as expected. You can't create a directory that ends with . (DOT) in windows. Windows will remove the dots automatically. So the function is not caring about the dots.
You can do something like.
string directoryToCheck = Path.GetFullPath(@"C:\CurrentDir..");
bool isDirExist = Directory.Exists(directoryToCheck);
Best wishes,
Navaneeth
|
|
|
|
|
Hi all.
I would like to write a program that will function as a client on a remote computer. The idea is that at a given time i will be able to request specific actions from the client application. Remotely, of course.
Up to now i have considered two ways of doing this:
1. Use a DB on the server. The client will poll the DB for tasks at a standard rate and act as insrtucted there.
2. Use a web-service. The client will call a getTasks() method at a standard rate.
Both of these methods include polling the server at a fixed interval. This is necessary, since i need the client application to respond almost immediateley to server requests.
The thing is, i don't want these applications to interfere with the user's use-experience. I don't want him to feel that he has my application running in the background and polling every now and then.
So:
Are my concerns justified?
If so, what would you suggest as a substitute?
If not, which of the above would you suggest?
Thanks for reading all the way down here. I will really appreciate your responses.
SummerBulb.
|
|
|
|
|
I'd suggest you to got with choice 2. Use a web service or WCF to communicate with DB. This avoid tight coupling of client application with database.
SummerBulb wrote: I don't want him to feel that he has my application running in the background and polling every now and then.
So users won't be using your application directly? If not, you can start it and keep it in "System tray". Have a thread which does the polling.
Best wishes,
Navaneeth
|
|
|
|
|
N a v a n e e t h wrote: Have a thread which does the polling
I don't mind having the application in the background. My dillemma is concerning the CPU, memory and internet bandwidth.
|
|
|
|
|
SummerBulb wrote: My dillemma is concerning the CPU, memory and internet bandwidth.
It'd be a premature optimization. I'd suggest to make the application working first. Profile it and see whether it requires optimizations. BTW, you can consider few things when you develop.
1 - Ensure calls to Dispose() for all disposable objects - CLR manages the memory quite well and you don't have to worry much about it. Few classes in the .NET framework implements IDisposable and make sure you call Dispose() method on it to avoid resource leaks.
2 - Don't send unnecessary informations over the wire - I have found WCF services perform better than SOAP based web services. But you need to understand how WCF does the communication. When you send large objects/collections, it will be slow. So make sure you send only the necessary information.
Once you done with the application, profile it and find out the areas that can be optimized further.
Best wishes,
Navaneeth
|
|
|
|
|
Thank you very much for your replies.
Does the WCF differ much from the SOAP? (this must sound like a very silly question to someone whoe knows them both well...)
modified on Sunday, December 6, 2009 4:51 AM
|
|
|
|
|
SummerBulb wrote: Does the WCF differ much from the SOAP?
Yes. SOAP is a protocol where WCF is a framework for creating service oriented applications. WCF can communicate using SOAP protocol if needed. Here[^] is a good MSDN article on WCF's capabilities.
Best wishes,
Navaneeth
|
|
|
|
|
What's the "fixed interval"?
If "almost immediately" is less than 5 minutes, consider to could connect to a server, stay connected, and receive an event when there's a new task. No polling required, tasks arrive immediately.
If you're using WCF, you can do this Duplex Services[^].
|
|
|
|
|
I've had good success with having a Windows Service poll a database to get information on tasks to perform.
It could use a Web Service to access the database.
You can also define a custom action for the Windows Service that will allow the server to trigger the action of the client.
|
|
|
|
|
I am working on a Invoice Application in which a user can enter in the invoice line items by selecting the item number from a combobox within a DataGridView. I am looking for some sample code to do the following:
1. load a combox within a datagridview from a table
2. load other fields (item descr, item price from combobox table)
As always, thanks for the advice.
|
|
|
|
|
Try google. Copy and paste your first question into it's text box, and press search. It finds your answer, and even offers to correct your spelling at the same time!
Repeat.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
"Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"
|
|
|
|
|
I have an object named 'dv'
'dv' has a string property named 'refNumber'
There is also a string 'altString' = "refNumber"
Is there a way to use 'altString' to get that property from 'dv'?
string newString = dv.??altString??
-- should set newString the same as --
string newString = dv.refNumber
Thanks for your suggestions.
|
|
|
|
|
Reflection can do this. Use System.Reflection name space. You'd do something like (not tested)
PropertyInfo property = (PropertyInfo) dv.GetMembers().SingleOrDefault(info =>
info.MemberType == MemberTypes.Property &&
info.Name == altString);
string newString = string.Empty;
if (property != null)
newString = (string) property.GetValue(dv, null);
Best wishes,
Navaneeth
|
|
|
|
|
Thank you. Please forgive my ignorance, but where does 'refNumber' occur in your reply?
|
|
|
|
|
BDJones wrote: but where does 'refNumber' occur in your reply?
Quote Selected Text
You said it will be in altString variable. I am using that variable to compare against name. You can replace it with "refNumber" if you wish to.
Best wishes,
Navaneeth
|
|
|
|
|
|
|
|
Hi all,
how we can use the enum any simple Example of using the enum?
enum is data type or object?
Hope hear from you
Best Regards
|
|
|
|
|
Rameez Raja wrote: any simple Example
public enum Response
{
No
,
Yes
}
return Response.Yes ;
Rameez Raja wrote: enum is data type or object?
Read up on it[^] and then ask any specific questions you have.
|
|
|
|
|
Hi,
i can able to insert random letters in TableLayoutPanel with this code
private void form_Load(object sender, EventArgs e)
{
for (int a = 0; a < tableLayoutPanel1.ColumnCount; a++)
{
for (int b = 0; b < tableLayoutPanel1.RowCount; b++)
Random r = new random();
lable nl = new lable();
int x = r.nest(65,90);
char c = (char)x;
nl.text = c.tostring();
tableLayoutPanel1.Controls.Add(nl, a, b)
}
}
}
i couldn't able to insert chosen words into TableLayoutPanel .pls help me.
how to change the color of letters when they click answer.
thanks in avance.
|
|
|
|
|
Hi,
please use PRE tags to show code.
and show real code, something that might be acceptable to a compiler.
your code is filled with minor mistakes.
also don't create new Random() instances all the time, use one Random() over and over.
Add a Click handler to each Label, so you can change its color; you can reuse the handler for all Labels, and use its sender to identify which Label got clicked.
From what you show and ask, I expect you are pretty new to C#, and would benefit from studying a C# book to properly learn the basics.
|
|
|
|
|
Why does it call two ReferenceEquals methods when only one is needed? I have tried removing the one with null as a parameter and it works exactly the same. I don't understand its purpose.
return !ReferenceEquals(null, obj) &&
(ReferenceEquals(this, obj) || obj.GetType() == typeof(Foo) &&
Equals((Foo)obj));
|
|
|
|
|
When you override Equals() , you are saying that "your class objects has value equality rather than reference equality". The suspected code here is doing just a null check before doing the value equality. Calling members on a null reference will lead to exception. It can't just use if(obj == null) because if operator == is overloaded on the type and it calls Equals to do the equality, you will end up in infinite loop. Usually it is a recommended practice to overload operator == if you have overridden Equals and call Equals from operator overload.
Having said that, resharper is stupid in generating Equals and GetHashCode . You should never rely on the code what it generated. Resharper includes mutable objects in the hashcode calculation which will lead into severe issues.
Best wishes,
Navaneeth
|
|
|
|