|
Thanks,
I was afraid that it would be the case. I guess i'll have to engineer something...
darthBug
Join the dark side of the code
|
|
|
|
|
Hi everyone,
I am writing a server-client chat application where I have a ServerObject that is subclassed from MarshalByRefObject and is created as a Singleton. This ServerObject is acquired by the client by the GetActivator() method. Now, I wanted to add an event handler that will be raised when someone joins or leaves the chat room. So, I have done something like this-
<br />
public delegate void OnUsersJoinEventHandler(object sender, EventArgs e);<br />
public delegate void OnUsersLeaveEventHandler(object sender, EventArgs e);<br />
<br />
public class ChatServerObject : MarshalByRefObject<br />
{<br />
public event OnUsersJoinEventHandler UsersJoin;<br />
public event OnUsersLeaveEventHandler UsersLeave;<br />
<br />
protected virtual void OnUsersJoin(EventArgs e)<br />
{<br />
...<br />
}<br />
<br />
protected virtual void OnUsersLeave(EventArgs e)<br />
{<br />
...<br />
}<br />
}<br />
<br />
public class ChatClient<br />
{<br />
public ChatClient()<br />
{<br />
object server_obj = Activator.GetObject(typeof(ChatServerObject), "tcp://...");<br />
m_chat_server_object = (ChatServerObject)server_obj;<br />
<br />
m_chat_server_object.UsersLeave += new ChatServerObject(this.UsersLeft);....Line(1)<br />
}<br />
}<br />
So, you get the idea. Now, when the code compiles okay but when the runtime executes the line (1) above it throws an exception. The exception says the following-
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll. Getting the InnerException wasn't much insightful either. I can send you the full string of the InnerException if you think it might be useful. I tried to create another class that was subclassed from MarshalByRefObject but wasn't Registered as WKO; and that works fine. So, perhaps it has something to do with the fact that my server object is a WKO. Any insights into this problem will be useful.
|
|
|
|
|
Hi,
Below is my question on a similar problem and no one has responded since the last 3 days and I have posted it twice.
Anyhow, I am started to think it has something to delegates or events--just an assumption, as I have a similar design and it causes exception.
My problem is below somewhere if you want to have a look. I am searching and if I find anything I will let you know and if you find anything, I'd appreciate the same.
|
|
|
|
|
Hi!
How is your server object instantiated? Singleton? Single Call? Published directly?
It seems there's a problem on the server side either with object creation or event registration.
Could you post the server's constructor and more details regarding the server and client remoting configuration (TypeFilterLevel etc.)?
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
In MDIParent Form, I am using tableLayoutPanel control with two colomns and I want to open a child form in second column of tableLayoutPanel at runtime. Is this possible? Please reply as soon as possible.
|
|
|
|
|
Dear All,
I need to administrator the Indexing Service via the Web Application,
I did find a component that i good for desktop but not for web application.
Any suggestion would be highly appericated.
Thank you!
Nauman
"Mess with the Best, Die like the rest"
|
|
|
|
|
How do i create a program using c# to block unwanted access to certain website such as playboy.com?
|
|
|
|
|
If you are creating your own browser, then you could parse the urls/links for for words or sites in a dictionary. When a match occurs you could immediately redirect to another webpage.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
using system.ole
Hussaingreat
|
|
|
|
|
Listen ..
We're more than keen on helping you out, but this is absolutely too little information.
Or maybe I should just anwser just as thoughfully as you asked your question.
try this :
for (int i=1;i < 500; i++)<br />
{<br />
Console.WriteLine(i.ToString() + " : I need to give more information");<br />
}
|
|
|
|
|
Is there any build-in method to compare byte array or do I have to do it manualy ?
|
|
|
|
|
I don't believe there's a built in function, and I've seen some pretty *interesting* ways people have done it, but bytewise comparison is simple and fast unless you're talking GBs of data.
static bool compareByteArrays(byte[] arr1, byte[] arr2) {
int len, i;
for(i = 0, len = arr1.Length; i < len && arr1[i] == arr2[i]; i++);
return i == len;
}
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Hey
try this :
public static bool ArraysEqual(byte[] by1, byte[] by2)<br />
{<br />
if ( by1 == null )<br />
throw new ArgumentNullException("by1");<br />
if ( by2 == null )<br />
throw new ArgumentNullException("by2");<br />
<br />
if ( by1.Length != by2.Length )<br />
return false;<br />
<br />
for(int i=0; i < by1.Length; i++)<br />
{<br />
if ( by1[i] != by2[i] )<br />
return false;<br />
}<br />
return true;<br />
}<br />
Hope this helps
Cheers
|
|
|
|
|
Thank you both
I will so write my own one because I need an equivalent to memcmp, not returning a bool but an integer telling who is greater
|
|
|
|
|
Hello
I need to use a BinaryReader to read strings but I want to know how to prepare string in my file
This is to documentation comment :
Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time
Does it mean that a string can't be longer than 127 bytes (7 bits integer) ??
|
|
|
|
|
I use the following method to read files. Its pretty fast and then you could use regular expressions to find text within the returned string or what ever else you need to do with the content.
<br />
public string DecodeFile(string fullpath)<br />
{<br />
if (File.Exists(fullpath) == false)<br />
throw new FileNotFoundException();<br />
<br />
try<br />
{<br />
FileStream fStream = File.OpenRead(fullpath);<br />
byte[] buffer = new byte[fStream.Length];<br />
int bytesRead;<br />
bytesRead = fStream.Read(buffer, 0, buffer.Length);<br />
fStream.Close();<br />
fStream.Dispose();<br />
<br />
if (bytesRead <= 0)<br />
throw new Exception("Empty file.");<br />
<br />
Decoder decoder = Encoding.Default.GetDecoder();<br />
char[] cBuffer = new char[buffer.Length];<br />
<br />
int bytesConverted, charsConverted;<br />
bool bCompleted;<br />
<br />
decoder.Convert(buffer, 0, buffer.Length, cBuffer, 0, buffer.Length, false, out bytesConverted, out charsConverted, out bCompleted);<br />
return new String(cBuffer, 0, bytesConverted);<br />
}<br />
catch (Exception ex)<br />
{<br />
throw new Exception(ex.Message);<br />
}<br />
<br />
}<br />
Google search lead me to this info
"Well, its not quite that simple. int.MaxValue is the most the string class
itself could handle, you are right, but since characters take up two bytes,
that many characters would go way beyond the max possible allocation. The
best theoretical high value is 2^31(or 2147483648) characters, since that is
exactly how many would fit in memory. Practially it'd be much, much smaller."
http://bytes.com/forum/thread481655.html[^]
Just because we can; does not mean we should.
|
|
|
|
|
Hello
This can be good for little file but if you have to manage a few very big files it does not seems to be a good approach
And it does not give me the answer to my question : what is 7 bits encoded integer. Does it limit string lenght to 127 bytes ?
|
|
|
|
|
Take a look at the BinaryReader.Read7BitEncodedInt, BinaryWriter.Write7BitEncodedInt.
The 7 bits integer means that a 32 or 64 bit int can be written in a single byte if the value of the int does not exceeds 7bit (127 decimal). This is done to save space, i.e. an int instead of 4 or 8 bytes may be saved in a single byte.
|
|
|
|
|
Thank you
Finaly thank to you I've found on internet how to build an 7 bit encoded integer !
|
|
|
|
|
I work with a guy that is always talking about how many flops[^] a particular activity takes. Quoting him directly HOWEVER, when passing the information from method to method, an arraylist is not the most efficient taking up to 60,000 flops to pass the information therefore arrays are faster. I asked him once where he got this information and was told that somebody at Microsoft told him. Does anybody know where there is any written documentation about this? I would like to learn more about this to become a more efficient coder. References to information would be very helpful. I have Googled for this info and not found it, so any help is appreciated.
Hogan
|
|
|
|
|
With the risk of going completely out of line here ( forgive me if I do ) , but I think the term 'flop' is something that this particular engineer dreamed up himself. I've never encountered nor heard of 'flops' when parsing information.
What's more .. the engineer contradicts himself by say that arraylist is not the most efficient and a bit further up therefore arrays are faster Faster to what ?
Cheers
|
|
|
|
|
I believe he is referring to the term I linked to in my first article.
Hogan
|
|
|
|
|
Flops refers to the number of FLoating point Operations Per Second.
|
|
|
|
|
Have you tested it by collecting the DateTime before the method and the DateTime afterwards and then calculating the difference to see what is actually faster? I know your looking for documentation, but never throw out good old fashioned testing.
Just because we can; does not mean we should.
|
|
|
|
|
Yeah, I've done tests... Proved the exact opposite. But he wouldn't even look at my test program to see the results. I was hoping for more data... Not that it would be read.
Hogan
|
|
|
|