|
Hi,
I didn't look at your code as it was unformatted, lacking PRE tags. However I think you should read this[^].
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi all, I have some issues on Registering event, If you have any idea on my implementation please help me …
private SHDocVw.InternetExplorer browser;
HTMLDocument document;
HTMLDocumentEvents2_Event DocEvents;
This Event Fires well, when ever I click on any link the event is fired no issue on that. But when I click on the Text box the focus losts.
browser = (SHDocVw.InternetExplorer)pDisp;
DocEvents = (mshtml.HTMLDocumentEvents2_Event)document;
DocEvents.onclick += new HTMLDocumentEvents2_onclickEventHandler(DocEvents_onclick);
To over come this issues I have just implemented from one of the articles like bellow
public delegate void DHTMLEvent(IHTMLEventObj e);
[ComVisible(false)]
public class DHTMLEventHandler
{
public DHTMLEvent Handler;
mshtml.HTMLDocument Document;
public DHTMLEventHandler(mshtml. HTMLDocument doc)
{
this.Document = doc;
}
[DispId(0)]
public void Call()
{
Handler(Document.parentWindow.@event);
}
}
browser = (SHDocVw.InternetExplorer)pDisp;
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)browser.Document;
DHTMLEventHandler Handler = new DHTMLEventHandler(doc);
Handler.Handler += new DHTMLEvent(this.myCallback);
doc.onclick = Handler;
but it shows the bello error.
Ambiguity between 'mshtml.DispHTMLDocument.onclick' and 'mshtml.HTMLDocumentEvents_Event.onclick
So I have changed from mshtml.HTMLDocument to mshtml.DispHTMLDocument
Now there is no compilation error but while excecuting it shows the bellow error
System.NotImplementedException , NotImplemented “\r\n”
Somewhat I got the information that we have to use mshtml. IHTMLDocument2 So I have used as bellow
public delegate void DHTMLEvent(mshtml.IHTMLEventObj e);
[ComVisible(true)]
public class DHTMLEventHandler
{
public DHTMLEvent Handler;
mshtml.IHTMLDocument2 Document;
public DHTMLEventHandler(mshtml.IHTMLDocument2 doc)
{
this.Document = doc;
}
[DispId(0)]
public void Call()
{
Handler(Document.parentWindow.@event);
}
}
DispHTMLDocument dispDoc = (mshtml.DispHTMLDocument)browser.Document;
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)browser.Document;
DHTMLEventHandler Handler = new DHTMLEventHandler(doc);
Handler.Handler += new DHTMLEvent(this.myCallback);
dispDoc.onclick = Handler;
public void myCallback(IHTMLEventObj evo)
{
}
Now this runs good, but no event is fired while I click on the browser
If some one has any observation on that please guide me how to go with this. I am able to use IHTMLElementCollection and add events for each and every IHTMLElement But I am not interest in loop through all the elements and register events for each and every elements, rather want to regisert an event for a Document and from that I want to identify which element is clicked.
There are type of approaches.W3C Document Object Event Model.and Microsoft Event Object Model.
I think we can achieve the issues using Event Register and Bubbling
I know little bit on concept wise but not able to implement
If some one helps me … then it will be helpful for many…
Plese free to post your comments on that
Thanks for every one (those who involves in it)
|
|
|
|
|
I use AxSHDocVw.AxWebBrowser on a form. It work fine.
|
|
|
|
|
|
Hello,
I've been coding projects in Java for some time now and decided to move to C#. I have some difficulty using the notifyall equivalent of Java in C#. Here's how I use it:
In Java when I make a multithreaded application I use the Wait() command to make the thread sleep, and at some point I use the notifyAll command which makes all threads in the wait state continue operation (from then on it's usually a race over which gets the resources first and the others become blocked again.
Now the closest thing I have found to this in C# is the AutoRaiseEvent and ManualRaiseEvent classes.
How my program works is: There are usually 4-8 threads running asking a question from the class by putting the question in the input queue, the class (called Handler) gets the next question and puts the answer in the outputqueue along with the code that identifies the original question.
Up to now I've been using something like this:
While {!myHandler.hasAnswer(myQuestionCode))
{
Application.DoEvents();
}
unfortunatelly this uses up a lot of the CPU so it has to change.
I tried the following:
While {!myHandler.hasAnswer(myQuestionCode))
{
RaiseEventObject.WaitOne();
}
and when the Handler produces the answer it calls RaiseEventObject.Set();
I tried using this with AutoRaiseEvent but then only one of the Threads triggers and usually it's the wrong one so it goes back to WaitOne() and nothing happens.
I am now testing the ManualRaiseEvent and altering my code to this:
While {!myHandler.hasAnswer(myQuestionCode))
{
RaiseEventObject.Reset();
RaiseEventObject.WaitOne();
}
but still I see a problem, what if two threads pass the WaitOne stage and then before the others can become unblocked (among them the one whose answer has been given) the event is Reset , can that happen? or when the Set() command is sent ALL threads unblock?
If the above happens isn't there a chance that the handler (the calculations it does don't take much time) will trigger the Set while one of the threads is in part of the loop other than WaitOne ? if that happens and the Reset triggers, will the Set be lost?
Can anyone suggest corrections to my code or some sort of alternative?
I'm sorry if I did not explain it correctly, English is not my primary language, I tried explaining it as best as I can.
Thanks in advance for any help
|
|
|
|
|
|
Thank you for the reply I tried coding all options mentioned in the article but it does not seem to work for me.
I've tried many solutions using the following code to test them:
private void button1_Click(object sender, EventArgs e)
{
Thread t1 = new Thread(DoWork);
Thread t2 = new Thread(DoWork);
Thread t3 = new Thread(DoWork);
Thread t4 = new Thread(DoWork);
t1.Start("1");
t2.Start("2");
t3.Start("3");
t4.Start("4");
}
public static void DoWork(object a)
{
while (true)
{
lock (key) {
while (block)
{
Monitor.Wait(key);
block = true;
}
}
Trace.Write(a.ToString() + "|");
}
}
private void button2_Click(object sender, EventArgs e)
{
for (int i = 1; i < 2000; i++)
{
Trace.WriteLine("-");
lock (key)
{
block = false;
Monitor.PulseAll(key);
}
}
}
(this is the implementation from the document that was linked)
what it shows is something along the lines of :
1234-
-
-
12-
123-
1234-
what I want it to show is this:
1234-
1234-
1234-
1234-
1234-
meaning that when the notify is sent ( the - in the printout) all threads wake up
did I just understand the article wrong?
|
|
|
|
|
That's nearly there, but this won't work at all:
Cruces wrote:
while (block)
{
Monitor.Wait(key);
block = true;
}
One of the advantages of Wait/Pulse is you can have different conditions for each waiting thread:
lock( key )
while( !myHandler.hasAnswer(myQuestionCode) )
Monitor.Wait( key );
If you also need your UI thread to wait for the worker threads to run, then you're going to have to synchronize that separately.
Normally, you just want to put a loop around the condition so the worker thread keeps going when there is work to do and only Wait 's when there is nothing ready to do.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Thanks a lot mate I hadn't thought of trying that, I'll try implementing that over the weekend and testing it with as many clients as possible to see how it goes, again thank you very much for the help
|
|
|
|
|
Import data in excel with OPENROWSET
but i want set formats of cell like date(dd-MMM-yy),number
and text but all should be done by sql server
or in predefine excel sheet
but not through excel objects.
|
|
|
|
|
Hello,
is there a possibility to draw controls like in a graphic-program in layers? My problem is, that i want to have for example a panel with a transparent-png-file as background drawed over a button, but the button should be visible if there's a transparency in the png file. - and maybe for every control inside my form?
Is there any way to draw them without having the restrictions of the Panels and Controls and so on?
Many thanks
|
|
|
|
|
Hallo
I'm developing a C# .Net2 application built around a DGV.
Is it possible to have the DGV data refreshed automatically as the underlying data change?
I mean, is there any way to automatically PUSH changes from database to the grid (or the BindingSource)?
Thanks in advance
|
|
|
|
|
I have a no idea what a DGV is. You can create triggers in your DB, and I believe in newer versions of SQL Server, they can run .NET code.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I think you ment DataGridView Control by dgv??
If you are using dataadapter object you can easily reflect changes to db. All you need is a timer control, and calling update method of this adapter in Tick event of timer.
|
|
|
|
|
Well, that's not very efficient, I assume that's what he's trying to avoid.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
By looking the question that he asked i think this method is adequate for this question.
I agree that this is not the best way and not very efficient but anything not mentioned about performance, or other ways that already tried.
|
|
|
|
|
hallo and thanks for the replies.
By DGV I mean the DataGridView control, but it could be any control showing data.
Actually I was trying to avoid a timer, but the underlying database is a SQL2000 thus having no possibility of CLR into T-SQL.
As far as I understand, the logic flow would be:
data changes > trigger that broadcasts/sends a message > client application "listening" > performs a grid refresh
|
|
|
|
|
Sorry I thought you were trying to send data to database. Now i understood you are trying to refresh grid from database.
data changes > trigger that broadcasts/sends a message > client application "listening" > performs a grid refresh is the best way i think
|
|
|
|
|
Yes, your outdated database probably means you have no choice but to use a timer. Unless, you write some sort of external app that broadcasts to all users somehow, when data is changed. It depends on how many users you have, how often data changes, etc.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I have maximum 15 concurrent users (on that particular table in the db) with less than 10 changes per minute: hence, I think I'll go for a timer.
Only, I thought that newer .NET brought something better on the argument...
Thanks anyway
|
|
|
|
|
It's your database that is out of date, and your database that is the issue. The database needs to tell your program when it's been changed, or you need to keep asking, those are the two options.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
If your implementation utilises BindingSource there are several events that you should consider investigating.
BindingSource.CurrentChanged
BindingSource.CurrentItemChanged
BindingSource.ListChanged
The last of these is most likely to be of use to you.
Here[^] is a link to the BindingSource reference on MSDN. I am struggling along on 53.6 Kbs at the moment otherwise I would have given links to the events themselves.
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I want to gather the Mac address in the diffrent subnet.
Now,My programe(C#) can obtain the PC and Printer's Mac address by SNMP.
But i can not obtain the switches' Mac address by the programe.
I think i should obtain the switche's Mac address by the same programe.
isn't it?
Maybe there are some forbidden in my VLAN.it is right?
urgent help!
modified on Friday, September 18, 2009 5:09 AM
|
|
|
|
|
Hi,
I am working on shared add-in in c# for Excel. Let us consider 3 components A,B,C. Where A is a Shim,B is Shared an add-in(used IDTExtensibility interface) which creates all tool bars, menu items for Excel and C is an automation add-in which contains UDFs.
I have static property in Automaion add-in(C) which set/gets Excel Application object. Whenever OnConnection(..) of shared add-in is called from the framework, I am setting the Excel application object using this property. So When I type some UDF in Excel, it uses this Excel application object for further work on Excel.
Recently I tried to remove the Shim and put the VSTO on it. When I use VSTo, it doesn't use shared add-in.Here also I set the Excel application object by using static property. Now I have I enabled this Auotomation add-in(add-in->Options->Automation Tab).But when I type some UDF in Excel cell, excel object is not available that is set from VSTO.How do I pass reference to Excel object to Automation add-in so that the same Excel Object is available in Automation add-in when we type some UDFs.
What I observed here is VSTO and Automation add-ins are working in different AppDomains.
Please help me.
Thanks.
|
|
|
|
|
Please do not post the same question in multiple forums. Choose the appropriate one and stick to it.
|
|
|
|