질문하기질문하기
 

답변됨WMI Asynchronously in ASP.NET

  • 2009년 11월 18일 수요일 오전 4:07sonihm 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Hi,

    I am developing ASp.net app  using WMI.  I have one button and textbox in web form.
    When user click  button, I want to execute below program code under button click
    protected void Button1_Click(object sender, EventArgs e)

    { }

     



    I WANT TO EXECUTE BELOW CODE WHEN BUTTON CLICK OCCUR, How can I do it?

    using System;
    using System.Management;
    using System.Windows.Forms;

    namespace WMISample
    {
        public class WMIReceiveEvent
        {
            public WMIReceiveEvent()
            {
                try
                {
                    WqlEventQuery query = new WqlEventQuery(
                        "SELECT * FROM Win32_ProcessStartTrace WHERE ProcessName = 'notepad.exe'");

                    ManagementEventWatcher watcher = new ManagementEventWatcher(query);
                    Console.WriteLine("Waiting for an event...");

                    watcher.EventArrived +=
                        new EventArrivedEventHandler(
                        HandleEvent);

                    // Start listening for events
                    watcher.Start();

                    // Do something while waiting for events
                    System.Threading.Thread.Sleep(10000);

                    // Stop listening for events
                    watcher.Stop();
                    return;
                }
                catch(ManagementException err)
                {
                    MessageBox.Show("An error occurred while trying to receive an event: " + err.Message);
                }
            }
           
            private void HandleEvent(object sender,
                EventArrivedEventArgs e)
            {
                Console.WriteLine("Win32_ProcessStartTrace event occurred.");
            }

            public static void Main()
            {
                WMIReceiveEvent receiveEvent = new WMIReceiveEvent();
                return;
            }

        }
    }

답변

  • 2009년 11월 24일 화요일 오후 1:18SS. Kanagal, Jr. 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Hi,

    Apologizes for the late response as I was out for the week-end.
     
    Ok, in .Net only the compiled (at server side) ASP page will be delivered as HTML page to present it to the client. Here the client means the web browser, so you need not to specify where the browser is located that's taken care by the internet protocol and the .Net framework. You need to take care only the business logic implementation in your .aspx pages. So when you click a command button automatically it hits the server back to execute the code behind and comes back to the client to present the next content if any.
     
    In case of any validations that you may have like for example validating an email address or required data field entry checking etc... then it can be performed on the client side (remote) rather visiting the server to perform these as it would reduce the load on the server and also the traffic a bit. Here you will be controlling hitting the server only when its required. So you just need to write your code in the Click event of the button that's all.


    -Kanagal

모든 응답

  • 2009년 11월 19일 목요일 오후 12:28SS. Kanagal, Jr. 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    I think you can make use of the codebehind to write these code, however when the button is clicked it goes to the server.
    Is that you're looking to execute this code on the client side?

    Happy coding...
    -Kanagal
  • 2009년 11월 19일 목요일 오후 2:05sonihm 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hi,

    Currently, I am working on laptop,So server and client is on same PC.  I want to make sure it works on same system.

    In future , i want to run code on remote client PC.

    When i paste above code inder button click events,  it gives me error.  I assume b'se it has some private or public scope or multiple method etc issue.  I am still new in .net programming.

    Thanks


    Soni
  • 2009년 11월 24일 화요일 오후 1:18SS. Kanagal, Jr. 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Hi,

    Apologizes for the late response as I was out for the week-end.
     
    Ok, in .Net only the compiled (at server side) ASP page will be delivered as HTML page to present it to the client. Here the client means the web browser, so you need not to specify where the browser is located that's taken care by the internet protocol and the .Net framework. You need to take care only the business logic implementation in your .aspx pages. So when you click a command button automatically it hits the server back to execute the code behind and comes back to the client to present the next content if any.
     
    In case of any validations that you may have like for example validating an email address or required data field entry checking etc... then it can be performed on the client side (remote) rather visiting the server to perform these as it would reduce the load on the server and also the traffic a bit. Here you will be controlling hitting the server only when its required. So you just need to write your code in the Click event of the button that's all.


    -Kanagal