C# 在何处放置标签消息并仅在流程完成后显示?

C# 在何处放置标签消息并仅在流程完成后显示?,c#,asp.net,webforms,label,C#,Asp.net,Webforms,Label,我是初学者。从下面的代码创建视频后,我应该如何以及在何处为消息添加标签。 我想在流程完成后显示两条消息,标签1:视频创建成功,第二条消息是视频的视频路径。 我只想在过程完成(视频创建)后显示它 名称空间测试 { 公共部分类liveRecording:System.Web.UI.Page { //视频编解码器 AVIWriter=新AVIWriter(“MSVC”); 受保护的无效页面加载(对象发送方、事件参数e) { 字符串streamingSource=”http://xxx.sample.c

我是初学者。从下面的代码创建视频后,我应该如何以及在何处为消息添加标签。
我想在流程完成后显示两条消息,标签1:视频创建成功,第二条消息是视频的视频路径。
我只想在过程完成(视频创建)后显示它

名称空间测试
{
公共部分类liveRecording:System.Web.UI.Page
{
//视频编解码器
AVIWriter=新AVIWriter(“MSVC”);
受保护的无效页面加载(对象发送方、事件参数e)
{
字符串streamingSource=”http://xxx.sample.com:85/snapshot.cgi";
string login=“login”;
字符串password=“password”;
JPEGStream JPEGSource=新的JPEGStream(streamingSource);
JPEGSource.Login=登录;
JPEGSource.Password=密码;
JPEGSource.NewFrame+=新的NewFrameEventHandler(视频\新帧);
JPEGSource.Start();
}
公共bool IsRecording=false;
整数宽度=0;
整数高度=0;
Queue frames=new Queue();//存储要由记录器线程写入的帧的队列
私有void video_NewFrame(对象发送方,NewFrameEventArgs eventArgs)//NewFrame的事件处理程序
{
//从JPEG流源获取帧
//位图图像=eventArgs.Frame;
位图图像=(位图)eventArgs.Frame.Clone();//从源获取位图的副本
宽度=图像宽度;
高度=图像高度;
如果(IsRecording)
{
//将要编码到视频文件的当前帧排队
frames.Enqueue((位图)image.Clone());
}
如果(!IsRecording)
{
IsRecording=true;
螺纹th=新螺纹(DoRecording);
th.Start();
}
}
私有无效数据记录()
{
//writer.FrameRate=5;
字符串SavingPath=(Server.MapPath(“~\\video\\”);
string VideoName=“ICS_”+string.Format(“{0:yyyyMMdd_hhmmss}”,DateTime.Now)+“.avi”;
writer.Open(保存路径+视频名称、宽度、高度);
DateTime start=DateTime.Now;
while(DateTime.Now.Subtract(start).Seconds<30)
{
如果(frames.Count>0)
{
位图bmp=frames.Dequeue();
writer.AddFrame(bmp);//将帧添加到AVI文件
}
}
writer.Close();//关闭
}
}
}
我只想在过程完成(视频创建)后显示它

那么基本上应该使用AJAX。您的“开始编码”(或其他)请求应该很快完成,以便用户返回适当的页面。该页面应包含Javascript,以定期轮询服务器,查看任务是否已完成-您需要一些协调(例如,通过随机生成的“作业ID”提供给客户端)。您可以使用类似于“长轮询”的方法(AJAX触发一个请求,该请求需要等待作业完成或超时),或者只需每隔几秒钟发出一个快速轮询请求


如果您是web开发新手,恐怕这一切都不容易,但在一个基于HTTP请求和响应的世界中,您尝试执行的任务并不容易。

它需要始终ping服务器以检查视频状态。您可以尝试放置AJAX进度条来查看视频的进度。并且可以在进度条停止时显示消息。@Jon Skeet在internet上搜索/阅读了1小时,但仍然无法理解。我可以用这个
this.Label1.Text=“Message”吗?@Rajaram Shelar你能解释一下吗?我的意思是,你能给我一个如何做的代码或者一个链接吗?@Lynx:不,你需要明白,最初的页面请求应该是快速的。它可以启动一个长时间运行的任务,但是它应该会向浏览器返回一个响应。代码运行正常,但进度条根据线程运行时间停止(
thread.Sleep(2000);
)。问题是如何根据代码隐藏(
DoRecording()
)中的实际进程停止进度条?表示进度条停止是因为
doRecording()
进程已完成,而不是因为线程时间已过期。
namespace test
{
    public partial class liveRecording : System.Web.UI.Page
    {
    //video codec
    AVIWriter writer = new AVIWriter("MSVC");  

    protected void Page_Load(object sender, EventArgs e)
    {
        string streamingSource = "http://xxx.sample.com:85/snapshot.cgi";
        string login = "login";
        string password = "password";

        JPEGStream JPEGSource = new JPEGStream(streamingSource);
        JPEGSource.Login = login;
        JPEGSource.Password = password;
        JPEGSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
        JPEGSource.Start();
    }

    public bool IsRecording = false;
    int width = 0;
    int height = 0;

    Queue<Bitmap> frames = new Queue<Bitmap>(); //Queue that store frames to be written by the recorder thread

    private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) //event handler for NewFrame
    {
        //get frame from JPEGStream source
        //Bitmap image = eventArgs.Frame;
        Bitmap image = (Bitmap)eventArgs.Frame.Clone(); //get a copy of the Bitmap from the source

        width = image.Width;
        height = image.Height;

        if (IsRecording)
        {
            //enqueue the current frame to be encoded to a video file
            frames.Enqueue((Bitmap)image.Clone());
        }

        if (!IsRecording)
        {
            IsRecording = true;
            Thread th = new Thread(DoRecording);
            th.Start();
        }
    }

    private void DoRecording()
    {
        //writer.FrameRate = 5;
        string SavingPath = (Server.MapPath("~\\video\\")); 
        string VideoName = "ICS_" + String.Format("{0:yyyyMMdd_hhmmss}", DateTime.Now) + ".avi";
        writer.Open(SavingPath + VideoName, width, height);

        DateTime start = DateTime.Now;
        while (DateTime.Now.Subtract(start).Seconds < 30)
        {
            if (frames.Count > 0)
            {
                Bitmap bmp = frames.Dequeue();
                writer.AddFrame(bmp);//add frames to AVI file
            }
        }
        writer.Close();//close
    }
}
}