Click here to Skip to main content
15,882,698 members
Home / Discussions / C#
   

C#

 
GeneralRe: List not printing out hardcoded books already added to list Pin
Dave Kreskowiak31-Mar-21 10:33
mveDave Kreskowiak31-Mar-21 10:33 
GeneralRe: List not printing out hardcoded books already added to list Pin
Member 1451443231-Mar-21 10:43
Member 1451443231-Mar-21 10:43 
QuestionHow to convert a column of DataTable into integer values? Pin
Alex Dunlop29-Mar-21 5:30
Alex Dunlop29-Mar-21 5:30 
AnswerRe: How to convert a column of DataTable into integer values? Pin
Richard Deeming29-Mar-21 5:42
mveRichard Deeming29-Mar-21 5:42 
AnswerRe: How to convert a column of DataTable into integer values? Pin
Mycroft Holmes29-Mar-21 20:21
professionalMycroft Holmes29-Mar-21 20:21 
AnswerRe: How to convert a column of DataTable into integer values? Pin
Arfat M1-Apr-21 19:58
Arfat M1-Apr-21 19:58 
GeneralRe: How to convert a column of DataTable into integer values? Pin
Richard Deeming6-Apr-21 0:06
mveRichard Deeming6-Apr-21 0:06 
GeneralChanging value in variable from another called class Pin
StealthRT28-Mar-21 17:26
StealthRT28-Mar-21 17:26 
Hey all I have been racking my brain trying to figure out what it is I am missing from the code below in order for the value "7:50 pm" to be placed into the variable theCntDownTimerTime from the TinyWS.cs class.

Let say the code below starts out with the time "7:00 pm".

I send the command from PostMAN (7:50 pm) and it picks it up just fine and the jsonSent.changeCNT does have the correct value of "7:50 pm". However, after this it seems to lose that value once the timer updates in the clockCoiuntDown.xaml.cs page for the theCntDownTimerTime.ToLower(). That value is still the same value (7:00 pm) as it was when the program started up and read my text file to get the default time.

clockCountDown.xaml.cs

C#
namespace laptopWatcher {  
  public partial class clockCountDown: Window {  
    public string theCntDownTimerTime = "";  
  
    public clockCountDown() {  
      InitializeComponent();  
      //get countdown time  
      theCntDownTimerTime = getTimeToStart();  
    }  
  
    private void Window_Loaded(object sender, RoutedEventArgs e) {  
      var desktopWorkingArea = SystemParameters.WorkArea;  
      this.Left = desktopWorkingArea.Right - this.Width - 20;  
      this.Top = desktopWorkingArea.Top + this.Height - 30;  
      var ts = ((60 - DateTime.Now.Second) * 1000 - DateTime.Now.Millisecond);  
  
      clockTimer.Tick += new EventHandler(clockTimer_tick);  
      clockTimer.Interval = new TimeSpan(0, 0, 35);  
      clockTimer.Start();  
  
      //Populate the time once to show to user  
      bgTxt.Text = DateTime.Now.ToString("h:mm tt");  
      txt.Text = DateTime.Now.ToString("h:mm tt");  
  
      //check if time for count down  
      if (txt.Text.ToLower().Equals(theCntDownTimerTime.ToLower())) {  
        _timer.Stop();  
        TimeSpan time = TimeSpan.Parse(theCntDownTimerTime);  
        cdownTimer((_time).TotalSeconds);  
      }  
  
      _tws = new TinyWS();  
      Thread t = new Thread(new ThreadStart(_tws.startWS));  
  
      t.Start();  
    }  
  
    private void clockTimer_tick(object sender, EventArgs e) {  
      bgTxt.Text = DateTime.Now.ToString("h:mm tt");  
      txt.Text = DateTime.Now.ToString("h:mm tt");  
      Console.WriteLine(txt.Text.ToLower() + " vs " + theCntDownTimerTime.ToLower());  
    }  
  
    public string getTimeToStart() {  
      string line;  
  
      using(StreamReader sr = new StreamReader(Environment.CurrentDirectory + "\\timestart.txt")) {  
        line = sr.ReadLine();  
      }  
  
      return line.ToLower();  
    }  
  
    // etc etc....  
  }  
}


TinyWS.cs

C#
namespace laptopLogin {  
  class TinyWS: clockCountDown {  
    HttpListener listener = new HttpListener();  
    clockCountDown ccd = new clockCountDown();  
  
    public class receivedData {  
      public string changeCNT {  
        get;  
        set;  
      }  
      public int timeAdd {  
        get;  
        set;  
      }  
      public bool internet {  
        get;  
        set;  
      }  
      public bool shutdownNow {  
        get;  
        set;  
      }  
    }  
  
    public void startWS() {  
      var prefixes = new List < string > () {  
        "http://*:8888/"  
      };  
  
      foreach(string s in prefixes) {  
        listener.Prefixes.Add(s);  
      }  
  
      listener.Start();  
      Console.WriteLine("Listening...");  
  
      while (true) {  
        HttpListenerContext context = listener.GetContext();  
        HttpListenerRequest request = context.Request;  
  
        string documentContents;  
  
        using(Stream receiveStream = request.InputStream) {  
          using(StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {  
            documentContents = readStream.ReadToEnd();  
          }  
        }  
  
        Console.WriteLine($"Recived request for {request.Url}");  
        Console.WriteLine(documentContents);  
        HttpListenerResponse response = context.Response;  
  
        //Check out the response  
        receivedData jsonSent = JsonConvert.DeserializeObject < receivedData > (documentContents);  
  
        if (jsonSent.changeCNT.ToLower() != ccd.getTimeToStart()) {  
          //The default shutdown time has changed so update the txt file.  
          using(StreamWriter sw = new StreamWriter(Environment.CurrentDirectory + "\\timestart.txt", false)) {  
            sw.WriteLine(jsonSent.changeCNT);  
          }  
  
          ccd.theCntDownTimerTime = jsonSent.changeCNT;  
        }  
  
        //Reply  
        string responseString = "hit";  
        byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);  
        response.ContentLength64 = buffer.Length;  
        Stream output = response.OutputStream;  
        output.Write(buffer, 0, buffer.Length);  
        output.Close();  
      }  
    }  
  
    public void stopWS() {  
      listener.Stop();  
    }  
  }  
}  


So what would I be missing? It looks fine to me but just doesn't store the value over.

I also have tried:

C#
public string theCntDownTimerTime = "";  
public string _newCNT {  
  get {  
    return theCntDownTimerTime;  
  }  z
  set {  
    theCntDownTimerTime = value;  
  }  
}


And on the TinyWS.cs page I have it sending by like ccd._newCNT = jsonSent.changeCNT;

But that also does not hold the new value.
GeneralRe: Changing value in variable from another called class Pin
Richard Deeming28-Mar-21 22:15
mveRichard Deeming28-Mar-21 22:15 
QuestionHow to detect user email address when user clicks on a link sent to their email? Pin
Zeyad Jalil28-Mar-21 1:44
professionalZeyad Jalil28-Mar-21 1:44 
AnswerRe: How to detect user email address when user clicks on a link sent to their email? Pin
Dave Kreskowiak28-Mar-21 8:20
mveDave Kreskowiak28-Mar-21 8:20 
AnswerRe: How to detect user email address when user clicks on a link sent to their email? Pin
OriginalGriff28-Mar-21 9:59
mveOriginalGriff28-Mar-21 9:59 
AnswerRe: How to detect user email address when user clicks on a link sent to their email? Pin
Richard Deeming28-Mar-21 22:04
mveRichard Deeming28-Mar-21 22:04 
QuestionHow to access cell information and controls of DevExpress Spreadsheet Form from another form in the same application? Pin
Alex Dunlop25-Mar-21 2:43
Alex Dunlop25-Mar-21 2:43 
AnswerRe: How to access cell information and controls of DevExpress Spreadsheet Form from another form in the same application? Pin
OriginalGriff25-Mar-21 5:03
mveOriginalGriff25-Mar-21 5:03 
GeneralRe: How to access cell information and controls of DevExpress Spreadsheet Form from another form in the same application? Pin
Gerry Schmitz25-Mar-21 7:42
mveGerry Schmitz25-Mar-21 7:42 
GeneralRe: How to access cell information and controls of DevExpress Spreadsheet Form from another form in the same application? Pin
OriginalGriff25-Mar-21 11:09
mveOriginalGriff25-Mar-21 11:09 
AnswerRe: How to access cell information and controls of DevExpress Spreadsheet Form from another form in the same application? Pin
Gerry Schmitz25-Mar-21 7:40
mveGerry Schmitz25-Mar-21 7:40 
QuestionChecking for existing open forms Pin
Alex Dunlop24-Mar-21 23:26
Alex Dunlop24-Mar-21 23:26 
AnswerRe: Checking for existing open forms Pin
OriginalGriff24-Mar-21 23:38
mveOriginalGriff24-Mar-21 23:38 
GeneralRe: Checking for existing open forms Pin
Alex Dunlop25-Mar-21 0:08
Alex Dunlop25-Mar-21 0:08 
GeneralRe: Checking for existing open forms Pin
OriginalGriff25-Mar-21 0:37
mveOriginalGriff25-Mar-21 0:37 
AnswerRe: Checking for existing open forms Pin
Richard Deeming25-Mar-21 2:51
mveRichard Deeming25-Mar-21 2:51 
QuestionCopy a selected gridview row to the same gridview Pin
Member 1493285423-Mar-21 2:41
Member 1493285423-Mar-21 2:41 
AnswerRe: Copy a selected gridview row to the same gridview Pin
Gerry Schmitz23-Mar-21 7:08
mveGerry Schmitz23-Mar-21 7:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.