|
|
1) u can use a delegate if u want an object to have several method with same signature (ie, a family of Methods) but with different algorithm and u can select between these method dynamically using a delegate. Something like...
delegate double BinaryOperation(double a, double b)
BinaryOperation binaryOperation;
private double Add(double a, double b)
{
return a + b;
}
private double divide(double a, double b)
{
return a / b;
}
public static void BinaryOperationsButton_click(sender object, EventArgs e)
{
if(object is btnAdd)
binaryOperation = new BinaryOperation(Add);
else if(object is btnDivide)
binaryOperation = new BinaryOperation(Divide);
binayOperation.BeginInvoke(operand1,operand2,null,null);
}
|
|
|
|
|
I've seen similar examples but I still can't see the point.
What's wrong with this code:
{
if (sender.name == "btnAdd")
{
double result = Add(operand1, operand2);
}
if (sender.name == "btnDivide")
{
double result = divide(operand1, operand2);
}
}
for me makes reading and understanding simpler.
So, I am not using delegates, and worrying i'm missing something
Rob
|
|
|
|
|
the previous example did not do its job even though it show the delegates asynchronous ability.
Something assignable gives you the flexibility and scalability.
just look at this situation;
delegate void CipherInvoker(byte[] array);
CipherInvoker cipher;
public void ChooseCipher()
{
if(option == "RSACipher")
cipher = new CipherInvoker(RSACipher);
else if(option == "DESCipher")
cipher = new CipherInvoker(DESCipher);
CipherFile("blah", cipher);
}
public void CipherFile(string filname, CipherInvoker cipher)
{
// blah blah
cipher();
//blah blah
}
lets assume that , you found out new efficient and secure way of ciphering or u want to implement ciphering with a another alogorithm;
then u can implement it and u can use it without altering unnecessary places
u may change like
public void ChooseCipher()
{
if(option == "RSACipher")
cipher = new CipherInvoker(RSACipher);
else if(option == "DESCipher")
cipher = new CipherInvoker(DESCipher);
else if(option == "MyCipher")
cipher = new CipherInvoker(MyCipher);
CipherFile("blah" ,cipher);
}
|
|
|
|
|
I have an application and I am going to deploy it without making an EXE. J’t copy the release folder and run it. Are there any wrong of that or any disadvantage?
|
|
|
|
|
What do you mean without an EXE? The Release folder will contain an exe if the project type was console or winform application.
|
|
|
|
|
yes i did a mistake writting that..Ok t'me is that same we deploy the release folder and makeing an installation file..
Any disadvantage deploying release folder?
|
|
|
|
|
If you have a simple application that doesn't need work done before first run it's OK. You can just xcopy the directory.
If you have a more complex application you may be needing a setup program created. The setup application lets users choose components, location, language, etc for the application (i.e. the work that has to be done before the first run).
|
|
|
|
|
Hi folks,
Hope I am not posting a dead horse here. My search-fu is weak with this topic. Very little relevant info from google or cp searches.
Here is the scenario.
I am building 2 projects. One is an admin module for a database that will install sql server and configure a connection string and dump it into and encrypted file. The admin will then copy this file to the location of the setup files for the user module. When the users/admin installs the user module, I would like to read the connection string from the file located in the setup location, which could be local or on a network share or anywhere else accessible.
How can I get the location of the setup.exe file that the user started at runtime. I am using VS2005 Pro, C#, .Net 2.0. I am not using clickonce, I have created a setup project and installer class with onafterinstall event handler.
Forgot to mention this is a Windows Vista/XP desktop application not a web app.
I have looked at the Context[parameter] object, System.Reflection namespace, System.Environment, Application Object and am not getting it.
I would really appreciate any help you can give. I will probably feel really stupid when the answer hits.
Thanks much
Dave
modified on Sunday, June 8, 2008 3:16 AM
|
|
|
|
|
Hi!
IIRC there's no built-in way to access this information from inside a deferred custom action (that's what your OnAfterInstall event is).
So you'll have to pass all the information you need in your CA inside the CustomActionData property.
hth...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
mav,
Thanks much, I was beating this thing around for hours and couldn't figure out what was going on. You led me right to the information I needed to clear it up. For anyone interested, the installer properties are not available to the deferred custom actions. If you need to access these properties you have to pass them to the deferred custom action in the CustomActionData property then you can retrieve the information through the Context object. The following articles were also helpful (which i wouldn't have found without your help mav ).
http://msdn.microsoft.com/en-us/library/9cdb5eda.aspx[^]
and
http://msdn.microsoft.com/en-us/library/aa370905(VS.85).aspx[^]
Thanks again for the big assist!
Dave
|
|
|
|
|
Glad I could help.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
How can I connect to a scanner from my application and scan and save file in .jpg format? Can any 1 help?
|
|
|
|
|
I hope my reply is 'Immediate' enogh for you! We all want immediate help but it's very rude to ask for it. Also read point 2 in the How to get an answer to your question[^] post at the top of this forum.
This[^] may help.
Dave
|
|
|
|
|
Sorry for that . But actually I'm in a bit hurry. I need to scan pictures using scanner from my application and save them in my resource folder. But the problem is I have never worked with something scanner or printer or how to use them from C# application. Now it would be very help full for me if u tell me any way.
Thanking in Advance
Johnny
|
|
|
|
|
At the bottom of my previous message is a link that may help.
Dave
|
|
|
|
|
|
Saiyed Alam wrote: Sorry for that . But actually I'm in a bit hurry.
Aren't we all?
|
|
|
|
|
You forgot to mention that it's urgent in the message text - just using the subject for this is not enough.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Sorry for that . But actually I'm in a bit hurry. I need to scan pictures using scanner from my application and save them in my resource folder. But the problem is I have never worked with something scanner or printer or how to use them from C# application. Now it would be very help full for me if u tell me any way.
Thanking in Advance
Johnny
|
|
|
|
|
Saiyed Alam wrote: But actually I'm in a bit hurry
Actually, that doesn't matter because this is still a volunteer forum. Everyone who answers questions here does so simply because they like to help. But they have lives with other commitments. If you ask a good question you will get help, but only when those who volunteer have time.
|
|
|
|
|
I really don't think he's being urgent enough.
Maybe Christian's next article can be on "Getting Answers Fast - Communicating Urgency 101"
|
|
|
|
|
Quick!! hurry! hurry! panic! that's the best way to get you're code right...
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
If you restate your question with a good subject line help is available. With a good subject line your question and the answers can be found by others who have similar problems in the future.
Rob
|
|
|
|
|
Is their any way to determine the user define type or string or List.
I know there are some methods that can be used to determine primitive types like IsPrimitive. Now String and user define objects are reference type thats where the problem is. I would like to use some this like this
if(objtype.IsPrimitive)
hashtable.add(obj.name, obj.value) //that i can do
else if(objtype.isString)
hashtable.add(obj.name, obj.value) // call a recursive method to get their property value and //fill the hashtable. How?
else if(objtype.isString)
somemethod(obj); //how?
else if(objtype.isString)
hashtable.add(obj.name, obj.value) //How?
else if(objtype.isString)
call a recursive method //How?
|
|
|
|