|
I have a VS.net solution that has:
- server project
- client project
- shared library
- shared library 2
The server project publishes both shared library and the second shared library for remoting. The client properly registers itself to use the remoting objects. The client can successfully use the remoting objects.
Here is the question: I want shared library 2 to be able to access the remoting object “Shared library” by using remoting. I add all the necessary references. But – when I try to register the class as a client for remoting (by doing :
System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownClientType(typeof(Shared.MySharedClass), "http://127.0.0.1:8080/shared");
It fails with a remotingexception.
Is it possible to access other remoting objects from an object that is published for remoting?
|
|
|
|
|
I am trying to send lines of hex file to commPort wit the serial communication.
I am trying the StreamReader and ReadLine and using textfile to do this job.
My hex file is an Intel hex format for example look like below.
TextFile
:0341000002410079
:0B410000E4C2E8C2E9C2EAC2EB80FEA4
:00000001FF
I have no problem to build this example soultion.
but I get an error when I try to bress button (Sndf3) button.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at BaseTerm.SndF3(StreamReader fr) in baseterm.cs:line 174
at TermForm.SndF3_Click(Object sender, EventArgs e) in termform.cs:line 662
Any suggestion or code help will be great.
Salam Hamid
-----------------------------------------------------------------------------------
Her is My C# code.
baseterm.cs
public void SndF3(StreamReader fr)
{
string input ;
while((input = fr.ReadLine()) != null)
{
for(int i =0; i < (fr.ReadLine().Length); i++) // Line 174
{
Send((byte)input[i]);
}
frm.ShowMsg("Hex Line OK...");
}
}
//----------------------------------------------------------------------------------
termform.cs
private void SndF3_Click(object sender, System.EventArgs e)
{
StreamReader fr = File.OpenText("P401CR.hex");
BaseTerm.term.SndF3(fr); // Line 662
fr.Close();
}
|
|
|
|
|
Use StreamReader.Peek() rather to so the EOF, ReadLine() wont garenteee anything.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Adding on to what leppie said.
You are getting a null reference exception due to a simple misconception.
while((input = fr.ReadLine()) != null)
input is now equal to the line that was read from the stream, the important point is that line has been removed from the stream. So now the next line of code will eventually fail because:
for(int i =0; i < (fr.ReadLine().Length); i++)
Your loop reads in one line from the stream until it crashes or i is greater than the length of the last line read in (keep in mind you are reading in a line every time through the loop).
What you probably meant to write was:
for(int i =0; i < (input.Length); i++)
So that you process the line of input read in at the start of the while loop.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thank you James and leppie.
I used
for(int i =0; i < (input.Length); i++)
it works now.
Salam;)
|
|
|
|
|
Where can I find info on implementing time trials and registration keys in my programs?
|
|
|
|
|
|
|
Hello,
I am developing the application in compact framework using c#.I want to create the dynamic menu which will take values from database and on clicking on the menuitems (retrieved from database) certain functioning should happen.Can anybody tell me how should I achieve the event handling for this?
I am pasting the code herewith:
for(int i=0;i<arrmenu.length;i++)
{
="" query="select description from configMaster where tableName='Menu' and tblId=" +="" arrmenu[i];
="" record.open(query,con);
="" menuitem="" mymenu="new" menuitem();
="" mymenu.text="record.Fields[0].Value.ToString();
" mymenu.click="" eventhandler(mymenu_click);
="" menuitem1.menuitems.add(mymenu);
="" record.close();
="" }
="" }
="" private="" void="" mymenu_click(object="" sender,="" eventargs="" e)
="" <u="">I AM NOT ABLE TO DETECT HERE WHICH MENUITEM IS CLICKED.
//MessageBox.Show(mainMenu1.MenuItems.GetEnumerator().Equals(sender).ToString());
}
|
|
|
|
|
newtocsharp wrote:
I AM NOT ABLE TO DETECT HERE WHICH MENUITEM IS CLICKED.
[edited]
It should be obvious that, since you add an event handler at the menu item level, not at the menu level, that you must create and attach a new event handler to each menu item :
myMenu.Click += new EventHandler(myMenu_Click1);
... // ith iteration
myMenu.Click += new EventHandler(myMenu_Click2);
... // i+1 th iteration
myMenu.Click += new EventHandler(myMenu_Click3);...
[/edited]
(useless)
|
|
|
|
|
But even though you have to add an event handler to each item seperately, you can respond to multiple objects' events in one pprocedure. Use the sender argument to find out which item raised the event.
|
|
|
|
|
Hello,
Thanks for the reply.I have tried with sender.getType().getDefaultMember()
but getting an 'indexOutofRangeException'
Can you help me out which sender property shall I use to find the item.
|
|
|
|
|
private void myMenu_Click(object sender, System.EventArgs e)
{
int nIndex = this.menuItem1.MenuItems.IndexOf( (MenuItem)sender );
String s = this.menuItem1.MenuItems[nIndex].ToString();
MessageBox.Show("you've clicked on " + s);
}
|
|
|
|
|
Is it possible to use IO Completion Ports in C# or MC++? If so any suggestions on where to start?
-BestSnowman
|
|
|
|
|
|
BestSnowman wrote:
Is it possible to use IO Completion Ports in C# or MC++?
That depends on what you want to do, as the link AK gave you says IOCP isn't exposed directly by the framework. But Eric Gunnerson[^] confirmed in the early days of this forum that if IOCP is available the BeginRead /BeginWrite methods on the various Stream classes will make use of it.
[edit]The thread[^][/edit]
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Hi,
I'm a newbie in the C# world, having arrived from MFC land. I'm learning about C# and .NET by playing around with a Windows Form app. I'm also in the process of porting one of my CP articles to .NET.
Anyway, my question:
I've added an event handler to a control in the form, and would like it to do nothing in some circumstances -- in other words I want it to just call the parent's event handler. How is that done when it comes to events and delegates?
For example, I know that with MFC, if override the IDOK handler (OnOK), I can just call CDialog::OnOK to let it do its default behavior. But events in C#/.NET seem to work differently.
I appreciate your help.
Regards,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
Rememebr that you must override the method that generates the event. You're not in fact overriding the event. For example the OnClick method raises the Click event. The OnClick method is virtual and therefore can be overriden. To call the default you simply would call the base's OnClick method ie base.OnClick(). For example:
protected override void OnClick ( System.EventArgs e )
{
base.OnClick(e);
}
|
|
|
|
|
Thanks nero. That clears up a lot of things. I wasn't aware of the OnWhatever members, but now it makes sense. They get called whenever something happens and their job is to trigger their specific events via their respective delegate members. Cool!
So now then, let's suppose I have a form, and I decide to handle the Click event of one of my buttons. In this case, the code inside the OnClick method will execute independently. In other words, my event handler is just a notification that something happened; it doesn't give me any control over whether to still execute the parent's code or not. But what if I did want that type of control? Would I have to derive my own Button class and override the OnClick?
Thanks again,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
It would be a mistake for you not to call the parent's code, just as it is in MFC. Can you imagine if you override the OnPaint event and not call the parent's code. That would be dangerous, because the parent code most often than not is critical for it to function properly.
That being said however, if you really don't want to call the parent's code, then yes, you would have to derive your own Button class and override the OnClick.
Cheers
|
|
|
|
|
Alvaro Mendez wrote:
would like it to do nothing in some circumstances -- in other words I want it to just call the parent's event handler.
The pattern Microsoft uses (in all instances I know of) is the following:
Class Foo exposes an event named Bar, Foo also has a protected method called OnBar. OnBar does two different things, one is a side-effect of the other.
First, in the class that defines the event OnBar can include some processing but to my knowledge they just fire the event, leaving the processing to however that class calls OnBar. The Bar event is fired from within OnBar because events can only be fired while operating within the class that defines it, anywhere else you can only add or remove handlers.
The second thing that OnBar does is allow you to handle the Bar event without having to hookup another event handler, reducing a little overhead (though not much).
Because OnBar should only fire the event, you can also call OnBar yourself to fire the event outside of normal circumstances.
Another thing to note is that events (for the most part) are notifiers that something has happened so you can only respond to that thing happening. As you suggest later, in order to prevent the Click event from firing in certain circumstances you need to go to the source, the OnClick method, and not call base.OnClick in those cases.
Hope that makes some sense to you, my thoughts have been jumbled a bit lately.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
I am using Visual Studio .net to try to make a button work like a ReadLine method.
I am using the button along with a textbox. The button is supposed to confirm the textbox after I have typed something in. I then want the textBox to stop reading after I have clicked the button and the information has been submitted. Then it should work again.
I'm using the Button event handler but that only works one time.
|
|
|
|
|
Hello,
I am attempting to create a custom class that is inherited from XmlNodeList.
public class MyNLClass : XmlNodeList
{
public string MyFunction(string name)
{
}
}
I would like to add a few additional functions. when I create class, I am getting errors like:
MyNLClass' does not implement inherited abstract member 'System.Xml.XmlNodeList.Count.get'
MyNLClass' does not implement inherited abstract member 'System.Xml.XmlNodeList.GetEnumerator()'
MyNLClass' does not implement inherited abstract member 'System.Xml.XmlNodeList.Item(int)'
Any help would be appreciated.
Thanks
|
|
|
|
|
The XmlNodeClass is cannot be created. Notice that the constructor is protected. Therefore this class was meant to be inherited from. Basically the class is essentially abstract and so are the members for which you are receiving errors.
Therefore, if you inherit from this class, you must implement all methods and properties that are abstract on this class. ie you must define these methods in your class. That is why you are getting the above errors. It's complaining that you haven't implemented them.
|
|
|
|
|
This more for my curiosity than efficiency, necessarily.
Is there a more straightforward way to get the fully qualified domain name of the machine the process is running on?
This is what I have so far, and it works:
<br />
System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName());<br />
String hostName = ipEntry.HostName;<br />
In my case, at least, System.Net.Dns.GetHostName() returns just the name of my computer, not the domain name, too.
|
|
|
|