|
How to get all processes that comunicate via port 80?
thank you for any help
|
|
|
|
|
|
Is it possible to clear the CurrentCell property so that it doesn't point to anything in the grid at all? I've tried CurrentCell = new DataGridCell(-1,-1) as an analog to the SelectedIndex = -1 used in comboboxes, listboxes, and listviews, but CurrentCell is instead assigned to the existing cell 0,0.
|
|
|
|
|
Can you override inherited delegates? If so, how?
I have a control that inherits from GridView (i.e. myGridView). It has a deleglate to handle some custom stuff.
public PBGridView()
{
RowUpdating += new GridViewUpdateEventHandler( PreUpdate );
}
I have another control that inherits from myGridView (i.e. myMultiGridView). I want to have it's own RowUpdating and skip the inherited one. How do I override it or "remove" it from myMultiGridView?? or do I have to edit myGridView to handle where it's getting called from? I would like to take care of it in myMultiGridView (lowest inherited level).
Thanks, Jessica
|
|
|
|
|
lsugirljte wrote: Can you override inherited delegates? If so, how?
They hide that information in the documentation[^]
The OnRowUpdating method also allows derived classes to handle the event without
attaching a delegate. This is the preferred technique for handling the event in a derived class.
led mike
|
|
|
|
|
Thanks for the help but I'm worried about this part.
"Notes to Inheritors When overriding OnRowUpdating in a derived class, be sure to call the base class's OnRowUpdating method so that registered delegates receive the event. "
I don't want to call the base class's OnRowUpdating method because it has code that won't work with my inherited class.
Thanks, Jessica
|
|
|
|
|
You could try using the new keyword and redefine the event in your myMultiGridView class. For example
class GridView
{
public event RowUpdatingDelegate RowUpdating;
}
class MyMultiGridView : GridView
{
public new event RowUpdatingDelegate RowUpdating;
}
Now clients who subscribe to MyMultiGridView's RowUpdating event will not get notified when the base class fires the event, so you get your own RowUpdating event. Unfortunately, this only works if the client uses your class to subscribe to events. For example
GridView g = new GridView();
g.RowUpdating += ...
MyMultiGridView g = new MyMultiGridView();
g.RowUpdating += ...
|
|
|
|
|
I found that this worked fine.
base.RowUpdating -= new GridViewUpdateEventHandler(base.PreUpdate);
Thanks, Jessica
|
|
|
|
|
I'm converting a 1.1 application to 2.0. There is some heavy use of Hashtable as well as two Hashtable = Hashtable.Synch(new HashTable); Is there a Generics equivalent??? I've not been able to find one.
|
|
|
|
|
I found this on the web a while back:
public class SafeDictionary<TKey, TValue> : IDictionary<TKey, TValue>
{
private readonly object syncRoot = new object();
private Dictionary<TKey, TValue> d = new Dictionary<TKey, TValue>();
#region IDictionary<TKey,TValue> Members
public void Add(TKey key, TValue value)
{
lock (syncRoot)
{
d.Add(key, value);
}
}
public bool ContainsKey(TKey key)
{
return d.ContainsKey(key);
}
public ICollection<TKey> Keys
{
get
{
lock (syncRoot)
{
return d.Keys;
}
}
}
public bool Remove(TKey key)
{
lock (syncRoot)
{
return d.Remove(key);
}
}
public bool TryGetValue(TKey key, out TValue value)
{
lock (syncRoot)
{
return d.TryGetValue(key, out value);
}
}
public ICollection<TValue> Values
{
get
{
lock (syncRoot)
{
return d.Values;
}
}
}
public TValue this[TKey key]
{
get
{
return d[key];
}
set
{
lock (syncRoot)
{
d[key] = value;
}
}
}
#endregion
#region ICollection<KeyValuePair<TKey,TValue>> Members
public void Add(KeyValuePair<TKey, TValue> item)
{
lock (syncRoot)
{
((ICollection<KeyValuePair<TKey, TValue>>)d).Add(item);
}
}
public void Clear()
{
lock (syncRoot)
{
d.Clear();
}
}
public bool Contains(KeyValuePair<TKey, TValue> item)
{
return ((ICollection<KeyValuePair<TKey,
TValue>>)d).Contains(item);
}
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int
arrayIndex)
{
lock (syncRoot)
{
((ICollection<KeyValuePair<TKey, TValue>>)d).CopyTo(array,
arrayIndex);
}
}
public int Count
{
get
{
return d.Count;
}
}
public bool IsReadOnly
{
get { return false; }
}
public bool Remove(KeyValuePair<TKey, TValue> item)
{
lock (syncRoot)
{
return ((ICollection<KeyValuePair<TKey,
TValue>>)d).Remove(item);
}
}
#endregion
#region IEnumerable<KeyValuePair<TKey,TValue>> Members
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
return ((ICollection<KeyValuePair<TKey,
TValue>>)d).GetEnumerator();
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator()
{
return ((System.Collections.IEnumerable)d).GetEnumerator();
}
#endregion
}
|
|
|
|
|
Thanks. I'm not sure if your code is what I ended up with....but I used it as a basis for creating this (comments were pulled to keep my sanity with all of the lt/gt symbols) ::
using System;
using System.Collections.Generic;
using System.Collections;
namespace System.Collections.Generic
{
public class ThreadSafeDictionary<TKey, TValue> : IDictionary<TKey, TValue>
{
private readonly object syncRoot = new object();
private Dictionary<TKey, TValue> d = new Dictionary<TKey, TValue>();
#region IDictionary<TKey,TValue> Members
public void Add( TKey key, TValue value )
{
lock ( syncRoot )
{
d.Add( key, value );
}
}
public bool ContainsKey( TKey key )
{
lock ( syncRoot )
{
return d.ContainsKey( key );
}
}
public ICollection<TKey> Keys
{
get
{
lock ( syncRoot )
{
return d.Keys;
}
}
}
public bool Remove( TKey key )
{
lock ( syncRoot )
{
return d.Remove( key );
}
}
public bool TryGetValue( TKey key, out TValue value )
{
lock ( syncRoot )
{
return d.TryGetValue( key, out value );
}
}
public ICollection<TValue> Values
{
get
{
lock ( syncRoot )
{
return d.Values;
}
}
}
public TValue this[ TKey key ]
{
get
{
lock ( syncRoot )
{
return d[ key ];
}
}
set
{
lock ( syncRoot )
{
d[ key ] = value;
}
}
}
#endregion
#region ICollection<KeyValuePair<TKey,TValue>> Members
public void Add( KeyValuePair<TKey, TValue> item )
{
lock ( syncRoot )
{
if ( d.ContainsKey( item.Key ) )
throw new InvalidOperationException( String.Format( "The item for key {0} already exists in the dictionary.", item.Key ) );
d.Add( item.Key, item.Value );
}
}
public void Clear()
{
lock ( syncRoot )
{
d.Clear();
}
}
public bool Contains( KeyValuePair<TKey, TValue> item )
{
lock ( syncRoot )
{
return ( ( ICollection<KeyValuePair<TKey, TValue>> )d ).Contains( item );
}
}
public void CopyTo( KeyValuePair<TKey, TValue>[] array, int arrayIndex )
{
lock ( syncRoot )
{
( ( ICollection<KeyValuePair<TKey, TValue>> )d ).CopyTo( array, arrayIndex );
}
}
public int Count
{
get { return d.Count; }
}
public bool IsReadOnly
{
get { return false; }
}
public bool Remove( KeyValuePair<TKey, TValue> item )
{
lock ( syncRoot )
{
return ( ( ICollection<KeyValuePair<TKey, TValue>> )d ).Remove( item );
}
}
#endregion
#region IEnumerable<KeyValuePair<TKey,TValue>> Members
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
return ( ( IEnumerator<KeyValuePair<TKey, TValue>> )d );
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return ( ( System.Collections.IEnumerable )d ).GetEnumerator();
}
#endregion
}
}
|
|
|
|
|
hi
i want to export My DataGridView to an Excel 2003, How to do ??
( I found an article from this site that convert datagrid to excel :
http://www.codeproject.com/csharp/export2excel.asp[^]
but it is datagrid and i want DataGridView .. how to do ??)
thanks
|
|
|
|
|
Hi have a problem with a remoting tool Im making. When you select a computer, it connects and shows data from the server on that end - however, if I close that form, and then try again with a different IP, I get an exception:
System.Runtime.Remoting.RemotingException: the channel 'http' is not registered with remoting services at System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(IChannel chnl)
How can I "unregister" my channel and launch a new connection?
Here is my connection at the mo:
public void InitRemoteServer()<br />
{<br />
try<br />
{<br />
RemotingConfiguration.RegisterWellKnownClientType(<br />
typeof(procDLL),<br />
"http://" + connIP + ":" + connPORT + "/procDLL");<br />
}<br />
catch (Exception ex)<br />
{<br />
}<br />
}<br />
<br />
private void viewProcesses_Load(object sender, EventArgs e)<br />
{<br />
HttpChannel channel = new HttpChannel();<br />
ChannelServices.RegisterChannel(channel);<br />
try<br />
{<br />
InitRemoteServer();<br />
}<br />
catch (Exception ex)<br />
{<br />
ChannelServices.UnregisterChannel(channel);<br />
}<br />
server1 = new procDLL();<br />
string allProcsRunning = server1.return_processes();<br />
}
Thanks, Ben.
|
|
|
|
|
You are only showing your init and load logic. What about your close logic?
Are you unregistering and closing your connection when you close???
Check that.
Also....you may want to look into changing your server as a part of you application. Something like File/Change server...
Then close the current server connection and open the new one. If you get that logic working then you know what you must do when you close.
If you shutdown your app without the clean close and run your app again, the channel is still hanging around.
|
|
|
|
|
Closing the channel is the bit thats confusing me - its only a form within the app, so when I close that form, I need to close the current connection, so that when I relaunch the form again it will accept a new IP.
Im new to remoting, so sorry if I am missing something simple lol
Here is the full code to date:
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Runtime.Remoting;<br />
using System.Runtime.Remoting.Channels;<br />
using System.Runtime.Remoting.Channels.Http;<br />
using RemProcs;<br />
<br />
namespace Softcode_Network_Tools<br />
{<br />
public partial class viewProcesses : Form<br />
{<br />
public viewProcesses()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
public Form1 frm1;<br />
public string connIP;<br />
public string connPORT = "8011";<br />
<br />
public void InitRemoteServer()<br />
{<br />
try<br />
{<br />
HttpChannel channel = new HttpChannel();<br />
ChannelServices.RegisterChannel(channel);<br />
RemotingConfiguration.RegisterWellKnownClientType(<br />
typeof(procDLL),<br />
"http://" + connIP + ":" + connPORT + "/procDLL");<br />
}<br />
catch (Exception ex)<br />
{<br />
<br />
}<br />
}<br />
<br />
private void viewProcesses_Load(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
this.Text = "View " + ((Form1)frm1).selected_name + "'s Processes";<br />
label1.Text = "Connecting to: " + ((Form1)frm1).selected_ip + "...";<br />
connIP = ((Form1)frm1).selected_ip;<br />
<br />
try<br />
{<br />
InitRemoteServer();<br />
}<br />
catch (Exception ex)<br />
{<br />
InitRemoteServer();<br />
}<br />
server1 = new procDLL();<br />
string allProcsRunning = server1.return_processes();<br />
string[] arrProcs = new string[200];<br />
char[] splitter = {':'};<br />
arrProcs = allProcsRunning.Split(splitter);<br />
this.listView1.Items.Clear();<br />
this.listView1.BeginUpdate();<br />
<br />
for (int x = 0; x < arrProcs.Length; x++)<br />
{<br />
if (arrProcs[x] != "-")<br />
{<br />
if (arrProcs[x] != " ")<br />
{<br />
if (arrProcs[x] != "")<br />
{<br />
ListViewItem lvi;<br />
lvi = new ListViewItem();<br />
lvi.Text = arrProcs[x];<br />
this.listView1.Items.Add(lvi);<br />
}<br />
}<br />
}<br />
}<br />
this.listView1.EndUpdate();<br />
listView1.Sorting = SortOrder.Ascending;<br />
label2.Text = "Windows Account Name: " + server1.return_user();<br />
label2.Visible = true;<br />
label1.Text = "Connected to: " + connIP + ".";<br />
}<br />
catch (Exception ex)<br />
{<br />
label1.Text = "Unable to connect to " + connIP + ".";<br />
MessageBox.Show(ex.ToString());<br />
}<br />
<br />
}<br />
<br />
private void button3_Click(object sender, EventArgs e)<br />
{<br />
this.Dispose();<br />
}<br />
}<br />
}
|
|
|
|
|
First : The code would be MUCH easier to view if you wrap it with <pre> and <\pre> instead of the code parameter.
Secondly : the code, as I read it, does not look good. For example, when you initialize the client you ignore exceptions. Not good. If you get a connection failure, your client is dead.
Finally : Does button3 close the application???? You should rename that to make it self-documenting. If it closes the form, then this.Dispose() will not close your connection for you!!! (Which is part of your problem)
I highly suggest you get get this book:
Advanced .Net Remoting 2nd Ed. Ingo Rammar/Mario Szpuszta (Apress 1590594177)
This is the top of the list for remoting education!!! It looks like you're creating your remote object incorrectly, there should be no reason for InitializeRemoteServer since InitializeClient does that job.
Good luck,
Michael
|
|
|
|
|
Hello I use WndProc(ref Message m) in a windows form.
If I use WndProc in a consol "dos" programm ( no windows form ) error message is :
WndProc(ref System.Windows.Forms.message) no suitable method found to override
Do you know why ? is this methoc can running in programm consol ?
Thanks
Vincent
|
|
|
|
|
You're not inheriting from a class which defines WndProc.
Sig cops got me...
|
|
|
|
|
Console applications don't normally setup their own Window message pump, so there's no WndProc in the Console class to override.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks very much for your answer.
Is it possible whith consol to detect usb Key insert ?
how replace this code for consol ? :
protected override void WndProc(ref Message m)
{
if (m.Msg == Native.WM_DEVICECHANGE)
{
if (!_loading)
{
LoadItems();
}
}
base.WndProc(ref m);
}
thanks again
Vincent
|
|
|
|
|
Well, you could run a message pump in your console app by calling Application.Run[^]. You could either create a hidden windows form, override the WndProc and pass that instance to Application.Run, or you could create a message filter, add it using Application.AddMessageFilter[^] and then simply call Application.Run .
|
|
|
|
|
thanks,
I am sorry I dont understant all.
In my consol programm how link application and event.
this is a part of my code, but dont work ?
An idea ?
thanks
namespace SYS_SERVEUR
{
class RemoteMain
{
[STAThread]
static void Main(string[] args)
{
lines of code ....
// here my new code to detect device change ?!?
TestMessageFilter mytest = new TestMessageFilter();
Application.AddMessageFilter(mytest);
Application.Run();
}
}
//here the event that I would like dtect ???
public class TestMessageFilter : IMessageFilter
{
protected const UInt32 WM_DEVICECHANGE = 0x0219;
public bool PreFilterMessage(ref Message m)
{
// Blocks all the messages relating to the left mouse button.
if (m.Msg == WM_DEVICECHANGE)
{
//Console.WriteLine("Processing the messages : " + m.Msg);
Console.WriteLine("TOTO");
return true;
}
return false;
}
}
}
|
|
|
|
|
Can i demo above program?
|
|
|
|
|
hi..
I am using .net ver 1.1(VS 2003),i need to call a web method asynchrously can any body provide some help...
pls provide some link which i can follow
|
|
|
|
|
This article on Asynchronous Method Invocation[^] may help you.
"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." - Rick Cook www.troschuetz.de
|
|
|
|