16,717
社区成员
发帖
与我相关
我的任务
分享 Public Class getproduct
'取产品
Private tid As Integer
......
Public Sub New(ByVal _Dc_ID As String, ByVal _site As String)
tid = Threading.Thread.CurrentThread.ManagedThreadId
......
End Sub
End ClassPrivate Sub prodsave(ByVal _name As String, ByVal _link As String)
Do
If tableid = Nothing Then
tableid = tid
Threading.Thread.Sleep(10)
If tableid = tid Then
......
tableid = Nothing
Exit Do
End If
Else
Threading.Thread.Sleep(getrand)
End If
Loop
End Sub
Module wc
Public tableid As Integer = Nothing
End ModulePrivate Sub prodsave(ByVal _name As String, ByVal _link As String)
Do
If tableid = Nothing Then
tableid = tid
Threading.Thread.Sleep(10)
If tableid = tid Then
......
tableid = Nothing
Exit Do
End If
Else
Threading.Thread.Sleep(getrand)
End If
Loop
End Sub
1: public class Contract
2: {
3: public string ID { get; private set; }
4: public string From { get; set; }
5: public string To { get; set; }
6: public decimal Fee { get; set; }
7:
8: public Contract()
9: {
10: this.ID = DateTime.Now.ToBinary().ToString().Replace("-", String.Empty);
11: }
12: }
1: public class HouseMovingCompany
2: {
3: private static HouseMovingCompany _instance = null;
4: public static HouseMovingCompany Instance
5: {
6: get { return (_instance == null ? _instance = new HouseMovingCompany() : _instance); }
7: }
8:
9: public List<Contract> Contracts { get; private set; }
10:
11: public HouseMovingCompany()
12: {
13: this.Contracts = new List<Contract>();
14: }
15:
16: public void MoveHouse()
17: {
18: if (this.Contracts == null || this.Contracts.Count == 0)
19: {
20: return;
21: }
22:
23: Contract contract = contract = this.Contracts[0];
24: this.Contracts.RemoveAt(0);
25:
26: if (!String.IsNullOrEmpty(contract.From) && !String.IsNullOrEmpty(contract.To))
27: {
28: Console.WriteLine("Move the house from {0} to {1}.", contract.From, contract.To);
29: }
30:
31: Thread.Sleep(5000);
32: }
33: }1: static void Main(string[] args)
2: {
3: HouseMovingCompany.Instance.Contracts.Add(new Contract { From = "WuDaokou", To = "LinDa Road", Fee = 500 });
4:
5: while (HouseMovingCompany.Instance.Contracts.Count > 0)
6: {
7: HouseMovingCompany.Instance.MoveHouse();
8: }
9: }1: static void Main(string[] args)
2: {
3: HouseMovingCompany.Instance.Contracts.Add(new Contract { From = "WuDaokou", To = "LinDa Road", Fee = 500 });
4: HouseMovingCompany.Instance.Contracts.Add(new Contract { From = "XiDan", To = "WangFujing", Fee = 1000 });
5: HouseMovingCompany.Instance.Contracts.Add(new Contract { From = "XiangShan", To = "The Forbidden City", Fee = 10000 });
6:
7: while (HouseMovingCompany.Instance.Contracts.Count > 0)
8: {
9: HouseMovingCompany.Instance.MoveHouse();
10: }
11: }1: static void Main(string[] args)
2: {
3: HouseMovingCompany.Instance.Contracts.Add(new Contract { From = "WuDaokou", To = "LinDa Road", Fee = 500 });
4: HouseMovingCompany.Instance.Contracts.Add(new Contract { From = "XiDan", To = "WangFujing", Fee = 1000 });
5: HouseMovingCompany.Instance.Contracts.Add(new Contract { From = "XiangShan", To = "The Forbidden City", Fee = 10000 });
6:
7: Thread thread = null;
8:
9: while (HouseMovingCompany.Instance.Contracts.Count > 0)
10: {
11: thread = new Thread(new ThreadStart(HouseMovingCompany.Instance.MoveHouse));
12:
13: thread.Start();
14: }
15: }1: public void MoveHouse()
2: {
3: if (this.Contracts == null || this.Contracts.Count == 0)
4: {
5: return;
6: }
7:
8: Contract contract = null;
9:
10: lock (this.Contracts)
11: {
12: contract = this.Contracts[0];
13: this.Contracts.RemoveAt(0);
14: }
15:
16: if (!String.IsNullOrEmpty(contract.From) && !String.IsNullOrEmpty(contract.To)) 17: {
18: Console.WriteLine("Move the house from {0} to {1}.", contract.From,contract.To);
19: }
20:
21: Thread.Sleep(5000);
22: }