c# How to wait all thread finished

  • For example ,wait 10 threads terminate

  • thread function :

 

c# fixed length queue

//固定长度队列
public class FixedSizedQueue
{
public Queue<TimeSpan> q = new Queue<TimeSpan>();

public int Limit { get; set; }
public void Enqueue(TimeSpan obj)
{
q.Enqueue(obj);
if (q.Count > Limit)
q.Dequeue();

}
}

//新建

FixedSizedQueue fNew = new FixedSizedQueue();
fNew.Limit = 30;

//入队

Stopwatch sw = Stopwatch.StartNew();
。。。dosomething
sw.Stop();
fNew.Enqueue(sw.Elapsed);

//计算平均值

double doubleAverageTicks = fNew.q.Average(timeSpan => timeSpan.Ticks);
long longAverageTicks = Convert.ToInt64(doubleAverageTicks);
TimeSpan tsNew = new TimeSpan(longAverageTicks);

来源文章:

https://stackoverflow.com/questions/5852863/fixed-size-queue-which-automatically-dequeues-old-values-upon-new-enques
https://stackoverflow.com/questions/8847679/find-average-of-collection-of-timespans/8847711

How to use log4net in c# console application

  • First , add local log4net.dll to reference
  • In project—>Properties—>AssemblyInfo.cs , add this line

  • change App.config to :

  • in Program.cs , use log4net like this :

emulate CDRCatch to catch VMS txt CDR

Part 1   learn and compile exsisting 

In MyExcel.cs ,  find a reference to

If really need this component ?

solution is :


Now this program can be compiled , When it is normally running on server 24 , the interface is this form :


Part 2  How to simulate a run-time environment

  • First , install filezilla server in local machine ,  set username , pwd ,and home folder
  • Second , create a sql server DB for test , here is all needed script

CreateDBSQL

  • Then , config connection string in catcher program
  • Create Catcher_VMS.cs for VMS cdr format
  • final the program can run normally .

Part 3 Code analyze 

  • Catcher_InsertThread.cs  only duty for insert cdr into db ,  cdr is come from

But , where m_CDRPool was EnQueue ?   in  Catcher.cs ‘s Worker()  function , processcdr function do it .

 

Part 4 VMS side cdr format 

here is the zip file :  20180718160119_09

in this file , exist such column of CDR :

  • next  , look at how SH ‘s catcher deal with CDR file , it is in this function

Catcher_misc.cs ‘s

 

Part 5 Q&A

  • what CatcherName,CDRID,SwitchID mean ?

CatcherName is the name of catcherlist .


Switch mean each FTP server ,  it include

 

it is defined in Catch.cs ‘s worker function  

and assigned from store procedure :


  • How to create a test FTP server on win 10
  • what is the purpose of catcher ‘s filter ?

Part 6 DB 

CreateDBSQL

Appendix

  • Visual studio :  expand all code —> Ctrl + M + P ,  Unexpand all code —> Ctrl + M + O
  • How to delete split container control :  click the control , then press escape , then press delete key .
  • How to convert yyyy-MM-dd HH:mm:ss fff  to datetime

 

See Also

 

TODO

———————————————–  2018-8-15

关闭窗口前提示:  否则线程泄露

窗口版本号,日期

程序图标

VMS format 读到 go 的时候,跳过, 不报错

设置连接串的地方

rateplan, help , about 去掉

右边2个listview设置固定时间刷新  —  10 分钟

Settings

  • local ftp server login :  liuyang  ,  piercing

 

How to use asternet send command to asterisk

  • asternet download site :

https://github.com/AsterNET/AsterNET/

 

  • asterisk server side config  (manager.conf)

 

deny + permit mean only allow 103.244.191.246 this IP  visit

read = call mean afer connect AMI and asterisk  , asterisk only send call event to AMI ,this can avoid too many event been sent to AMI , since AMI is UDP connection .

  •  modify of asternet program :

a) in

after

 

add

 

their cresponding function is :

 

above code will let AMI recv call event include :  dialbegin , dialend , and hangup ,  then write these info in datagridview


add a button , in its click event , write :

 

 

this will generate 100 calls to asterisk , especially notice :

 

without this property , calls will not success . this answer come from my ask queston in :

 

https://github.com/AsterNET/AsterNET/issues/146

 

  • here is full code    AsterNET   ,  pls check  winform project .

 

 


2018-6-1 modify 

 

上述方法是把 cdr 写到 datagridview 里, 但是,当cdr非常多的时候就不适合, 因此, 换一种方法, 只记录打通的电话次数和total duration ,  实现如下:

 

在 form 类定义

 

 

in some buttone ‘s click event , add :

 

in manager_DialEnd function , add

 

in call-hangup-events , add

 

 

textbox2  and textbox3 use to write calls and durations


 

如何实现周期性的点击按钮

in winform class , define

 

in construct function , write :

add function

 

start timer