Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
부모글 보이기/감추기

별로 ^^; 특별한 팁은 아니지만,,, 그래도 하나의 "아이디어" 라고 할만한 것이기에 소개합니다.
그러니까, 문제는 스마트 클라이언트의 "이벤트" 발생이 기본적인 "Internet_Zone" 에 위배되기 때문에 어쩔 수 없이 클라이언트 측에 보안설정을 강요받게 되는 데요.

만약, 순전히 이벤트로 인한 보안설정만 필요한 경우라면 다음의 팁으로 해결하시는 것을 권해 드립니다. 모든 상황에서 쓸 수 있는 방법은 아니지만, 적절하게 쓸 수 있는 상황도 있을 것 같기 때문에. ^^


소스 출처 : http://msdn.microsoft.com/msdnmag/issues/04/10/WebQA/default.aspx

Q We are considering hosting a Windows Forms control in an Internet Explorer Web browser for an intranet Web application. In order to avoid the issue of passing managed events from the Windows Forms control back to unmanaged JScript® code (we may not be able to ask all of our users to make the security changes necessary to allow this), I am thinking of having the JScript code poll the Windows Forms control (maybe four times per second) inquiring, basically, whether any events have fired that the JScript code needs to know about. In rough form, the JScript would look something like this:

window.setInterval(checkWinformEvents, 250);
var bCheckingEvents;
function checkWinformEvents() {
      if(!bCheckingEvents) {
            bCheckingEvents = true;
            var sEvents = objWinform.AnyEventsToReport();
            bCheckingEvents = false;
            if (sEvents) handleWinformEvents(sEvents) ;
      }
}

The managed method, AnyEventsToReport, would then return something like "Double-click on line 14 of List view," and so on. Is it a good idea to check Windows Forms events from JScript?


A Having the JScript code poll the Windows Forms control seems a little weird, but it would give you a workaround for the security restrictions put in place by Internet Explorer. There are a few problems with the code snippet, but nothing that is insurmountable. For instance, where exactly do you make the second call to setInterval? No loop is evident.

The bottom line is that this program is really not robust in the face of exceptions. Plus, there's some uninitialized data in there and you treat a string as a bool, which is a bad idea. Also, why are you doing a re-entrancy check on a method which is not recursive?

You should probably write it like this instead:

window.setInterval(checkWinformEvents, 250) ;
function checkWinformEvents() 
{
    try
    {
        handleWinformEvents(winform.AnyEventsToReport());
    }
    finally
    {
      window.setInterval(checkWinformEvents, 250) ;
    }
}
[Editor's Update - 12/6/2004: setInterval evaluates an expression each time a specified number of milliseconds has elapsed and until the timer is removed with the clearInterval method. As such, it does not need to be called again every time the checkWinformEvents function is invoked.]






[최초 등록일: ]
[최종 수정일: 3/31/2005]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-동일조건변경허락 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.

비밀번호

댓글 작성자
 




[1]  2  3  4  5  6  7  8 
NoWriterDateCnt.TitleFile(s)
197정성태7/30/20211509.NET : 63. Spectre.Console
196정성태10/28/20193183장치 관리자처럼 각 장치들에 할당된 리소스(예: Memory Range) 상태를 코드로 알아내는 방법
195정성태4/25/20192990Extracting Text from an Image Using Tesseract in C#
194정성태4/25/20192741Parse the Command Line with System.CommandLine
193정성태8/2/20175634.NET : 62. github - C# to JavaScript, WPF to JavaScript and Samples
192정성태6/29/20165172.NET : 61. TreeLib: Balanced Binary Trees ? Rank Augmented, for .NET
191정성태10/13/20156376.NET : 60. MICROSOFT TRANSLATOR HUB
190정성태6/20/20157092Win32 : 6. UMDH Visualizer - Memory profile viewer
189정성태1/19/20148709.NET : 59. QR 코드를 ASP.NET과 WPF에서 사용하는 방법
188정성태1/15/20148901.NET : 58. 윈도우폰 7 - 안면인식, Cartooning...
187정성태1/14/20148841.NET : 57. BCL에서 제공되는 컬렉션에 만족하지 못한다면? [1]
186정성태6/26/20138781.NET : 56. The managed way to retrieve text under the cursor (mouse pointer)
185정성태9/27/20129653.NET : 55. Face Detection with Emgu CV in C# and WPF
184정성태9/23/20128488.NET : 54. What was that sound Visual Studio? Audio Editor Beta For VS 2012 (plus free sounds library too!)
183정성태4/19/201210256.NET : 53. Virtual Router 소스 코드 및 실행 파일 (C#)
182정성태4/16/201210834.NET : 52. SharpDX [1]
181정성태3/3/201214152.NET : 51. .NET에서 DirectX를 이용하여 스크린 캡쳐를 빠르게 하는 방법 [3]
180정성태3/3/20129327.NET : 50. Restart Manager 를 이용하여 .NET 에서 잠긴 파일을 소유하고 있는 프로세스 찾는 방법
179정성태1/14/20128651.NET : 49. WebAPI Developer Preview 6: Self Hosted Mode Example
178정성태10/31/201110727.NET : 48. app.config의 supportedRuntime 예시
177정성태10/15/20119628.NET : 47. Irony - Language Implementation Kit
176정성태7/22/20119558.NET : 46. Manual Validation with Data Annotations
175정성태5/18/201111295Win32 : 5. UuidCreateSequential
174정성태5/4/20119772.NET : 45. NTrace v2 now available (think Managed VS2010/.Net 4 Event Tracing for Windows)
173정성태4/12/201111203레지스트리 : 11. BHO를 IE와 탐색기에서 선택적으로 로드하고 싶다면?
[1]  2  3  4  5  6  7  8