Click here to Skip to main content
14,576,820 members
Rate this:
Please Sign up or sign in to vote.
I'm working on developing Chrome Extension for several weeks. I have almost completed a demo version of chrome extension now. but I have one problem I don't know so that I wanna get some help from you guys.I've written the host in c# lang My host program is running even though the chrome browser was closed. and then my host program is launching again when chrome browser was re-open. which means my host programs are stacking whenever chrome browser was all closing then re-opening. how can I solve this problem? Plz, help me and advice me.

Thanks in advance :D


What I have tried:

I tried to control the host app using this code


[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);

private delegate bool EventHandler(CtrlType sig);
static EventHandler _handler;

enum CtrlType
{
  CTRL_C_EVENT = 0,
  CTRL_BREAK_EVENT = 1,
  CTRL_CLOSE_EVENT = 2,
  CTRL_LOGOFF_EVENT = 5,
  CTRL_SHUTDOWN_EVENT = 6
}

private static bool Handler(CtrlType sig)
{
  switch (sig)
  {
      case CtrlType.CTRL_C_EVENT:
      case CtrlType.CTRL_LOGOFF_EVENT:
      case CtrlType.CTRL_SHUTDOWN_EVENT:
      case CtrlType.CTRL_CLOSE_EVENT:
      default:
          return false;
  }
}


static void Main(string[] args)
{
  // Some biolerplate to react to close window event
  _handler += new EventHandler(Handler);
  SetConsoleCtrlHandler(_handler, true);
  ...
}


but this code is not working and not exiting the host app
Posted
Comments
Richard MacCutchan 30-Jun-20 5:12am
   
I cannot see any connection between the above code and a Chrome extension. Also, your application appears to set a console handler and then terminate. I suspect that is not what you want it to do.
member5320 4 days ago
   
I just want to know when is the browser is closing and when on browser closing event the host application must also be killed.
Richard MacCutchan 4 days ago
   
Sorry, I still do not see what that has to do with the above code.
member5320 3 days ago
   
I've found some code in c to close the native app like this


std::string req;
while(!(req=read_request()).empty())
{
//process request and send response
}




and this is my c# code to get the data from the browser


private static string OpenStandardStreamIn()
{
using var stdin = Console.OpenStandardInput();
string input = "";
int length = 0;
byte[] bytes = new byte[4];
stdin.Read(bytes, 0, 4);
length = BitConverter.ToInt32(bytes, 0);
byte[] buff = new byte[length];
stdin.Read(buff, 0, buff.Length);
input += Encoding.UTF8.GetString(buff);
return input;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100