|
The problem is, it's not correct OO to write non-related methods in a baseclass, since the base class is only to contain the basic methods and the subclasses contain their own methods, which are used only for them. Chest.Open() belongs to Chest. You can't open a Coin for example. Maybe I should reconsider my design, I don't know. Currently, a GameObject is something laying on the game world floor. However, I also use GameObject to simply put non-world-interactive sprites on the screen. Perhaps I could make an IPickupable and so on..
|
|
|
|
|
Then you could use an enum defining all possible actions for any game object. The base class has an abstract property for the allowed actions, and every derived class would return the actions valid for that class. Then you could call a function public void PerformAction(enum myAction) on your (derived) game objects (that function is abstract in the base class).
|
|
|
|
|
Hi all,
I just recently stepped into a strange problem.
I am making async calls to a method that scans files for "strange stuff"
public delegate HandleCheckResult(long id);
private void GetResult(long id)
{
System.Threading.AutoResetEvent ev = new System.Threading.AutoResetEvent(true);
HandleVirusCheckResult proc = Scan;
IAsyncResult async = proc.BeginInvoke(id, HandleResult, ev);
ev.WaitOne();
}
private void HandleResult(IAsyncResult async)
{
HandleCheckResult proc = (HandleCheckResult)((System.Runtime.Remoting.Messaging.AsyncResult)async).AsyncDelegate;
retVal = proc.EndInvoke(async);
((System.Threading.AutoResetEvent)async.AsyncState).Set();
}
It looks somehow like the code fragment above.
Everything works fine in my win-form application, but now I ported it to a Windows Service and get ArgumentOutOfRangeException on the EndInvoke method...
(index out of range, should not be negative and smaller than the collection)
If anybody could be so kind and point me into a direction... I am somehow lost right now...
Thanks in advance,
cheers
Hoernchenmeister
|
|
|
|
|
Hi,
When an exception is thrown on the worker thread started with BeginInvoke it is trapped and rethrown when EndInvoke is called. The exception will be happening somewhere in your Scan method and the first thing to do is find out where. Wrap the EndInvoke in a try..catch block and dump the full text of the exception out to a file, e.g. System.IO.File.WriteAllText("log.txt", ex.ToString()).
The stack trace will contain the line number where the exception was thrown and get you started on finding out what went wrong.
Alan.
modified on Tuesday, May 25, 2010 1:02 PM
|
|
|
|
|
Thanks a ton Alan,
that was exactly what I was looking for
best regards
Andy
|
|
|
|
|
Hi
I have a code as below
public class classname{
// first method
public bool methodtest()
{
string inputcallmethod = "methodtest2";
bool blnBurstsuccess = true;
Type testcall = typeof(classname);
object obj = System.Activator.CreateInstance(testcall);
string[] strnparam = new string[3]{this.par1, this.par2, this.par3 };
try
{
blnBurstsuccess = (bool)testcall.InvokeMember(inputcallmethod, BindingFlags.Public |BindingFlags.Instance | BindingFlags.InvokeMethod, null, obj, strnparam);
}
catch (Exception e)
{
blnBurstsuccess = false;
}
return blnBurstsuccess;
}
//second method
public bool methodtest2(string[] strparam)
{
--- some function
return bool varibale
}
}
This code returns an error as the "method methodtest2 not found".
I am not able to figure out the reason.While debugging, the try part is not executed.
Thanks,
|
|
|
|
|
Hi,
There is one small error which is not obvious.
Instead of
string[] strnparam = new string[]{this.par1, this.par2, this.par3 };
do this
string[] strnparam = new string[]{this.par1, this.par2, this.par3 );
object[] args = new object[] { strnparam };
and pass the args array to Type.InvokeMember. This will make it look for a method with one array parameter. Passing strnparam directly was making it look for a method with three parameters.
Alan.
|
|
|
|
|
what does object initializer do?? I mean, when we use it using new key word, then constructor should be called, but it is written on the msdn site that constructor is not called. If constructor is not called then how does the values are assigned?? What exactly the story is??
|
|
|
|
|
Muzammil Saeed wrote: but it is written on the msdn site that constructor is not called.
Where did you see that? If you look here[^] it states explicitly that the constructor is called.
It's time for a new signature.
|
|
|
|
|
Richard MacCutchan wrote: Where did you see that? If you look here[^] it states explicitly that the constructor is called.
If you look here[^] it says:
Object initializers let you assign values to any accessible fields or properties of an object at creation time without having to explicitly invoke a constructor.
I think this is what is confusing the OP.
|
|
|
|
|
David Skelly wrote: I think this is what is confusing the OP.
And yours truly.
It's time for a new signature.
|
|
|
|
|
Keyword "explicitly"; I guess it would call the default constructor and populate the properties right after that.
I are Troll
|
|
|
|
|
Exactly right, it takes a couple of readings to recognise this.
It's time for a new signature.
|
|
|
|
|
Can you post a link to where you found this?
My signature "sucks" today
|
|
|
|
|
Muzammil Saeed wrote: it is written on the msdn site that constructor is not called
If you read carefully, it actually says: without having to explicitly invoke a constructor. Note the key word explicitly, there.
The constructor is still called, the initializer is just a short-hand way to create and populate an object in one step. What actually happens at runtime is that a no-argument constructor is called to create an instance, and then the properties on that instance are populated with the specified values, one by one. The initializer just saves you a bit of typing. That's particularly useful if you are using anonymous types because then you can assume a no-argument constructor and auto-implemented properties so you don't have to code up an entire class. Also useful for collections where you just want to load up a list of entries and start using them.
|
|
|
|
|
|
Hello,
How can i check email if it's valid? I mean not the syntax but the email itself . Is there anyway to check it using the exchange server (the email is in the same domain) or using the SMTP server?
|
|
|
|
|
Do you want to check whether the Email address is valid or Not?
Sebastian
|
|
|
|
|
No,
I want to check if the email address really exist
|
|
|
|
|
The only way I know of to do that is to send an email and wait for a response from the server. The exception you're looking for is:
SmtpFailedRecipientsException
You could also NOT send an email and simply verify that the server exists with a ping.
http://msdn.microsoft.com/en-us/library/4971yhhc(v=VS.100).aspx[^]
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
This article covers almost areas of email validation.
You should, however, also look at some of the comments made towards the end of the article.
My signature "sucks" today
|
|
|
|
|
|
Hi,
It doesn't help so well.
It stucks and wait on some step.
where do i need to write the email address and the smtp server
|
|
|
|
|
There really isn't a completely reliable way. The checks you can do are these, in rough order of difficulty...
a) Check that the email address is in the correct format.
b) Parse out the server and see if you can do a DNS lookup on it.
c) Connect to the SMTP server on port 25 at the server name given in the mail address. On connection you should receive the following:
"220 smtpservername.com ESMTP"
For a further check send "HELO yourservername.com"
You should receive "250 smtpservername.com"
At this point, you at least know the user wasn't lying about the presence of an SMTP server at that address. Now you actually can ask the server whether the user exists without sending any mail. You would do it like this:
You send "MAIL FROM:<you...yourservename.com>"
And receive back "250 OK"
You send "RCPT TO:<user...smtpservername.com>"
And receive back "250 OK"
You now know that the user address exists on the server, and that the server is ready to receive mail for that user. There are various errors that might occur instead. "550 No such user" indicates the address is bad. "551 User has moved try <anotherservername.com>" indicates that the user used to have an address, but no longer does.
In reality servers behave in different ways, so you really can't infer too much. Either 550 or 551 essentially means "no such user." Additionally servers may return other errors, based on their state at the time, so if you're going to do this in a robust manner you need to handle all the possible responses. Few sites go to the trouble of implementing all this.
|
|
|
|
|
It always give me "250 OK"
on RCPT to:
even if the email is not correct ("fdfdfd@fjdkfjkdfjdk.cklclkdl")
|
|
|
|