|
I think your best bet is to create a proxy class for your external library and route all calls through your proxy. Which means, you should not invoke your external library directly. It should be done via this proxy class.
Mimic the event in your proxy class. When items are added, keep the event handlers in a list. Create a method something like ClearInvocationList() in the proxy class, loop through all the event handlers in the list and unregister the event. Clear the list.
You can implement this cleanup in destructor also. But it is not recommended as finalization is performance costly. Look at implementing IDisposable instead.
Sample code follows, (uncompiled and exceptions not handled)
class ExternalLibraryProxy
{
List<EventHandler> subscriptions = new List<EventHandler>();
public event EventHandler ThemeChanged
{
add
{
ExternalLibrary.ThemeChanged += value;
subscriptions.Add(value);
}
remove
{
ExternalLibrary.ThemeChanged -= value;
subscriptions.Remove(value);
}
}
public void ClearInvocationList()
{
foreach(EventHandler handler in subscriptions)
ExternalLibrary.ThemeChanged -= handler;
subscriptions.Clear();
}
}
Hope this makes sense.
|
|
|
|
|
I think the following will be more neat than the previous one.
As said in the previous post, create a proxy class.
class ExternalLibrayProxy
{
public event EventHandler ThemeChanged;
public ExternalLibrayProxy(){
ExternalLibray.ThemeChanged += EventHandlerMethod;
}
~ExternalLibrayProxy(){
ExternalLibray.ThemeChanged -= EventHandlerMethod;
}
void EventHandlerMethod(object sender,EventArgs args){
if(ThemeChanged != null)
ThemeChanged(sender,args);
}
} In this you don't need to keep the handlers explicitly in a list. When the class destructor is executed, your external library's event will get deregistered. You can implement IDisposable here to avoid overhead of finalization.
|
|
|
|
|
I'm afraid I can't insert a proxy.
As I wrote before the subscribers are also in an external library and subscribe to the ExternalLibrary.ThemeChanged directly.
That is some neat code though, I appreciate your effort.
edit:
typo
modified on Wednesday, October 22, 2008 4:03 AM
|
|
|
|
|
Hello,
I have to use a smoothing algorithm in my COde. I am using Visual C++ .Net 2008 with 3.5 framwork.
I am reading a data through serial port from a target device and this data is store into a XML file. I have to display(plot) this data on the window. For ploting the waveform, i read the data from the XML file, and draw(Plot) the point using "Drawline" function. but the curve generated is not in Smooth shape. It shows some noise(like steps).So in this case I want to use smoothing algorithm but dont know how to use it.So plz can anyone tell me how to use smoothing algorithm? its urgent so plz help me out.
Thanks and Regards,
Abhijit
|
|
|
|
|
How on earth is this a C# or ASP.NET question ?
Christian Graus
Driven to the arms of OSX by Vista.
"Iam doing the browsing center project in vb.net using c# coding" - this is why I don't answer questions much anymore. Oh, and Microsoft doesn't want me to.
|
|
|
|
|
Please post the questions in their appropriate forums. As per ur question you should use Anti-aliasing techniques. That should smooth out the graph a bit. But for complete smoothening, try to search for some free Vector drawing libraries!
-------------------------------------------
It's code that drives you - Shyam
|
|
|
|
|
Thanks for reply.
You say post this questions in their appropriate forums. But there is no Message board for Visual C++ .Net 2008. Which message board, i have to post this question, you suggest me?
|
|
|
|
|
|
Please do help me with the following problem.
In my C# Application Program, I have a DataGridView control. There are several rows and columns without data in it. And I need some type of a control (say, a lable or a button or a textbox - any control of my choice) to be able to dragged and dropped on this DataGridView so that it fits into the cell when I drop the control.
This dragged control in reality is do be drawn (or created) at runtime, but for the time being if I can get a predefined control to get the desired functionality, that would suffice.
Please do help with this. I checked this forum as well as a few others but couldn't find an answer. Also, please do explain how I get the drag-drop functionality to any control as well.
Thanks in advance!
|
|
|
|
|
I haven't tried, but DragEnter and DragDrop events will be the way to get started.
|
|
|
|
|
This is a most unusual requirement, most people just move the data around (there are lots of articles for that) I have never heard of DD a control before. Why do you need to drop a control into a DGV.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Well, yeah it sounded unusual for me too.
I'll give you as much information as I can reveal. This is for some work of professional software. One of our clients wants one of their MIS SW redesigned. It is originally designed by some other company. Now we don't have the original codes but just the interfaces.
In simpler terms imagine that there is a sort of a time table - say for a week, with eight hours being shown for every day - that is the DGV. Now controls are the jobs - lets say so - and whoever assigns the orders should be able to drag them from a list or something and then place on the DGV on the relavent time period. Say, one job is to allocate teh time 10am - 11am on Monday. SO and so.
So they need the exact functionality, and here I am stuck in the middle of it not knowing anything. My PM wants to somehow create it. And he doesn't really care which way. So I'm allowed to use any kind of control I like.
Hope you understood. Please help if you can.
|
|
|
|
|
Why are you married to a DGV. I have used a custom control within a flow control which should allow control DD. Table layout control comes to mind as another possibility.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mm... Sorry I'm sorta new to this C# thing. Learning on the job more like.
So how do I use a custom control? Can you please provide some example or something?
|
|
|
|
|
Hello all,
I was not sure if I should throw this into C# or Asp.net forum, please move if you feel appropriate.
Situation:
Programming an ASP website that will allow scheduling and connecting to a remote Cisco router to help students learn to configure Cisco routers during their Cisco classes. If you did not know, Vista no longer has Hyperterminal as XP did, and Hyperterminal is no longer free. Aside from the fact that there are some open source/free TCP/IP clients out there, the need arises to make it as simple for the student as possible.
My solution was/is to provide the solution via a webpage.
Problem:
I am quite new to ASP in general, though not C#. I wrote my own "Telnet" client that connects to the router and so far as I can tell works quite well. I am now trying to translate this Winforms application over to a ASP page that can be deployed onto the schools' server.
I used a TCPClient and Stream in the Winforms application to work out the telnet client part. In trying to translate this over to an ASP page, I am unclear exactly where I need to put the connection info (ie Page_Load). I need to keep the connection open to the router at all times. Currently in my Page_Load, I establish the connection and stream, however stream.DataAvailable does not seem to work (I was using it in a loop to get the greeting and passphrase prompt). However, if I just read the stream, in a combination of 2 separate Do..While loops, I get the initial greeting/passphrase prompt.
Aside from that issue, the stream is disconnected after the initial Page_Load. I need to be able to keep the connection alive for the duration that the user is logged into/viewing the webpage, and also process (via a textbox entry line on the same webpage) any commands sent by the person connected.
Can anyone provide some suggestions on how to accomplish this? Is anyone available via some form of Instant Messenger that can maybe help me out (I would not normally ask this, but, I do not know any other programmers in my area)?
Any help would be appreciated!
Thanks!
|
|
|
|
|
I know it doesn't really answer your question, but Vista does actually include a TelNet client. If you go into 'Programs and Features', then 'Turn Windows features on or off' and TelNet client is visible about six entries from the bottom (this is on Vista Home Premium). You can then run it from the Command Prompt as 'telnet', with 'telnet /?' explaining the command line arguments.
Modified: Corrected spellings.
|
|
|
|
|
Yes, true, telnet is available in that way. I did know about that, but thanks for the reply. Trying to tie together the two OS's though is really the issue. I guess I may be over complicating it a bit, we could just supply two different instruction sets. I figured the easy solution was a web page that does not depend upon the OS, if you get my drift. You are correct in that respect though.
|
|
|
|
|
Passing a SQL 2005 varBinary object (a Word document) to an instance of Word.Application --> Word.Document. This site has given me great guidance thusfar but I can't seem to make that connection with that SQL return (reader) of a word document and assigning it to a Word.Document object. I am working in C#, but a VB example is okay.
Kindly advise,
Dunloe
|
|
|
|
|
I'm not sure if this is what you're after but if you have stored the whole Word document in a varbinary field, save the contents to a file with doc extension. After that open it simply by executing the file in a shell (with Process.Start method) or use Word interop if you want to add it to an existing document.
Hope this helps,
Mika
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Mika,
I am sorry, I wasted your time. I have resolved my issue.
Thanks,
dunloe
|
|
|
|
|
No problem at all. You don't have to be sorry if your problem got solved.
If you feel afterwards that your post or my reply was somehow 'bad' or that something should have been figured out earlier, it's only part of the learning process and it goes both ways.
Mika
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
I am an existentialist that happens to be a programmer. There is no right or wrong. In our realm just syntax, and the sharing of that syntax.
All the best,
dunloe
|
|
|
|
|
hi...i wrote this code to read the input of textbox, and i wanna to classify each input to compute the given expression i want to store each operand in an index of arrayList ... as example:
suppose the input is : 22+99*7
then when i display the contents of the arrayKist results should be :
22
+
99
*
this is my Code please i realyy need help i stuck here:
private void equal_Click(object sender, EventArgs e)
{
ArrayList equation = new ArrayList();
string input = textInput.Text;
char[] Buffer = input.ToCharArray();
string tempString="";
try
{
FileStream historyFile = new FileStream("History.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(historyFile);
DateTime log = new DateTime();
sw.WriteLine(input + ": @ time " + log.TimeOfDay + "@ date " + log.Date);
sw.Close();
historyFile.Close();
}
catch( FileNotFoundException l)
{
MessageBox.Show("Logs File Not Found !!","Error Message");
FileStream exeptionFile = new FileStream("Errors.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(exeptionFile);
sw.WriteLine(l.ToString ());
sw.Close();
exeptionFile.Close();
}
for (int i = 0; i < Buffer.Length; i++)
{
if (char.IsDigit(Buffer[i]))
{
tempString += Buffer[i];
for (int j = i + 1; j < Buffer.Length; j++)
{
if(char.IsDigit (Buffer[j]))
tempString += Buffer[j];
}
}
else if (char.IsLetter (Buffer[i]))
{
tempString += Buffer[i];
for (int j = i + 1; j < Buffer.Length; j++)
{
if (char.IsLetter(Buffer[j]))
tempString += Buffer[j];
}
}
else if (char.IsSymbol (Buffer[i]))
{
tempString += Buffer[i];
for (int j = i + 1; j < Buffer.Length; j++)
{
if (char.IsSymbol(Buffer[j]))
tempString += Buffer[j];
}
}
equation.Add(tempString);
}
for (int t=0; t<equation.Count ;t++)
MessageBox.Show(equation[t].ToString());
}
while(1)
System.out.println("I love Palestine ");
|
|
|
|
|
You didn't quite indicate your exact problem.
However, perhaps you could use String.Split (for known operators) to find each operand and then test that operand is valid for example using Decimal.TryParse .
Hope this helps,
Mika
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
thanks mika...
my exact problem is that i cant get the operands exactly as extra operands are stored such the instead of storin just the 22 it stores also 2 and insted of 222 it stores two other operands 22 and 2 ... have i explained well??!!
there isnt just one operand to split around its all operands(mathmatical operations)...
what do think now?
thnx in advance..
while(1)
System.out.println("I love Palestine ");
|
|
|
|