如何distinquish在asp.net服务器端的并发进度条请求 [英] How to distinquish concurrent progress bar requests on server side in asp.net

查看:162
本文介绍了如何distinquish在asp.net服务器端的并发进度条请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现进度条显示完成状态的用户时背景视频的过程。它的工作原理以及对单个实例。但混合起来的时候,两个并行的视频处理启动。

I implemented progress bar to show completing status to users when video processes in background. it works well on single instance. but mixed it up when two concurrent video process started.

在两个视频的过程由同一时间两个不同的用户发起的,无论用户将看到喜忧参半从视频处理1时而状态,有时从另一个。

When two video processes initiated by two different users at same time, both users will see mixed progress status sometimes from video process 1, sometimes from another.

在服务器端视频处理与静态变量初始化。

Video process on server side initiated with static variable.

public static MediaHandler _mhandler = new MediaHandler();

通过

[WebMethod]
public static string GetProgressStatus()
{
    return Math.Round(_mhandler.vinfo.ProcessingCompleted, 2).ToString();
}

每隔几秒钟后进度条发送进度要求。

Progress request sent by progress bar after every few seconds.

现在我的问题是如何设置mediahandler对象,它可以在一个时间目标只有一个实例。

Now my question is how i can set mediahandler object which can target only one instance at a time.

例如进度条显示01视频处理的状态只有01

e.g progress bar 01 shows status of video process 01 only

进度条02显示视频处理的状态只有02

progress bar 02 shows status of video process 02 only

推荐答案

感谢分享想法,但遗憾的是没有解决办法解决并发问题,使用这几乎是所有用户共享的静态对象的情况。现在,我做了一些调整它解决了我的问题。

Thanks for sharing ideas but unfortunately no solution solve issue of concurrency in case of using static objects which is almost shared across all users. Now i made some adjustments which solved my problem.

而不是使用一个静态的对象,我使用的通用列表对象存储的所有并发进程对象的列表。这里是code。

Instead of using single static object, i used generic list object to stored all concurrent process objects in a list. Here is code.

public static List<MediaHandler> _lst = new List<MediaHandler>();

在哪里MediaHandler是类名负责处理视频。

Where MediaHandler is class name responsible for processing videos.

下面的函数负责发起视频处理

The following function is responsible for initiating video processing

public static string EncodeVideo(string Source, string Published)
{   
 MediaHandler _mhandler = new MediaHandler(); 
 ..............
 ..............
 _mhandler.vinfo.ProcessID = Guid.NewGuid().ToString(); 
// unique guid to attach with each process to identify proper object on progress bar and get info request
// add media handler object in concurrent static list
 _lst.Add(_mhandler);
 return _mhandler.vinfo.ProcessID; // retuned unique identifier
}

现在每个进度条请求过程ID必须发送以发送正确的视频处理对象的进度情况的功能。

Now with each progress bar request process id must be sent to function in order to send progress status of proper video processing object.

[WebMethod]
public static string GetProgressStatus(string ProcessID)
{
    string completed_process = "0";
    if (_lst.Count > 0)
    {
        int i = 0;
        for (i = 0; i <= _lst.Count - 1; i++)
        {
            if (_lst[i].vinfo.ProcessID == ProcessID)
            {
                completed_process = Math.Round(_lst[i].vinfo.ProcessingCompleted, 2).ToString();
            }
        }
    }

    return completed_process;
}

在处理完成100%,只是存储在对象中的所有视频信息和从静态同步列表中删除媒体处理对象。

Once processing completed 100% just store all video information in object and remove media handler object from static concurrent list.

if (_lst[i].vinfo.ProcessingCompleted >= 100)
{
    // remove from list of corrent processes if processes reach this point
    // store all information of completed process and remove it from list of concurrent processes
    // e.g
    VideoInfo current_uploaded_video_info = _lst[i].vinfo;
     _lst.Remove(_lst[i]);
}

在这样无限数量的并发进程和进度条的请求成为可能。

In this way unlimited number of concurrent processes and progress bar requests made possible.

这篇关于如何distinquish在asp.net服务器端的并发进度条请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆