Solved

C# Set timer for viewbag message

Posted on 2016-09-30
2
40 Views
Last Modified: 2016-11-09
I want a message to show/ change after 5 secs are up (I can do this in java script but I need to do it in C#)

I have a function that starts the timer and it works fine. However how can I change the viewbag message after the 5 sec.
Please show exp. code.

public ActionResult Balance()
        {
            var t = "false";

            SetTimer();

            while (exitFlag == true)
            {
                t = "true";
            }

            ViewBag.Response = t;

            return View();
        }

Open in new window


The Timer function work and it calls the OnTimeEvent ever 5 sec

private void SetTimer()
        {
            // Create a timer with a two second interval.
            System.Timers.Timer aTimer = new System.Timers.Timer(3000);
            // Hook up the Elapsed event for the timer. 
            aTimer.Elapsed += OnTimedEvent;
            aTimer.AutoReset = true;
            aTimer.Enabled = true;
        }

        private void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            //This does not work.....
            //ViewBag.Response = "true";

            exitFlag = true;
        }

Open in new window


Thx
0
Comment
Question by:quest_capital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 41824040
I can do this in java script
As you should be.

but I need to do it in C#
Not gonna happen. You need to firmly understand the concept of client/server and request/response. Then you will understand why you cannot do this on the server**.

** There is a way that you can kind of do this on the server, but it still entails using Javascript. Look at SignalR for more information.
1

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question