主頁 > .NET開發 > 基于C#的多邊形沖突檢測

基于C#的多邊形沖突檢測

2021-07-03 06:01:41 .NET開發

之前在專案上碰到了一個多邊形沖突檢測的問題,經百度、bing、google,發現目前已有的方案,要么是場景覆寫不全,要么是通過第三方類別庫實作(而這些第三方類別庫幾乎是無法逆向反編譯的),而專案中禁止使用第三方類別庫,遂自己實作了此演算法,

場景是這樣的,有兩個多邊形,多邊形A和多變型B,需要判斷多邊形B是否在多變型A內,即多邊形B是否是多邊形A的子多邊形,

 

 

 

  1. B的點全部在A內
  2. A的點全部在B外
  3. A的線段與B的線段沒有相交

接下來進行實作

第一步:創建多邊形類

 1 /// <summary>
 2 /// 多邊形
 3 /// </summary>
 4 public class Area_Dto
 5 {
 6     /// <summary>
 7     /// 點的集合
 8     /// </summary>
 9     public List<Point_Dto> Points { get; set; }
10     /// <summary>
11     /// 線段的集合
12     /// </summary>
13     public List<LineSagement_Dto> LineSagements { get; set; }
14 }
多邊形

第二步:創建點類

 1 /// <summary>
 2 /// 3 /// </summary>
 4 public class Point_Dto
 5 {
 6     public Point_Dto(double x, double y)
 7     {
 8         this.X = x;
 9         this.Y = y;
10     }
11     /// <summary>
12     /// 點的X坐標
13     /// </summary>
14     public double X { get; private set; }
15     /// <summary>
16     /// 點的Y坐標
17     /// </summary>
18     public double Y { get; private set; }
19 }

第三步:創建線段類

 1 /// <summary>
 2 /// 線段
 3 /// </summary>
 4 public class LineSagement_Dto
 5 {
 6     public LineSagement_Dto(Point_Dto start, Point_Dto end)
 7     {
 8         this.Start = start;
 9         this.End = end;
10         GetFuncParam(this);
11     }
12      /// <summary>
13      /// 線段的起始點
14      /// </summary>
15      public Point_Dto Start { get; private set; }
16      /// <summary>
17      /// 線段的終止點
18      /// </summary>
19      public Point_Dto End { get; private set; }
20      /// <summary>
21      /// 線段的型別
22      /// </summary>
23      public LineType_Enum FunType { get; set; }
24      /// <summary>
25      /// 線段為斜線是才有實際作用
26      /// 線段的斜率及線段與Y軸的交點
27      /// </summary>
28      public List<double> Params { get; set; } = new List<double>();
29      /// <summary>
30      /// 交點串列
31      /// </summary>
32      public List<Point_Dto> Intersection { get; set; } = new List<Point_Dto>();
33 
34      /// <summary>
35      /// 求當前線段的斜率,當當前線段為斜線時,同時是求出與Y軸的交點
36      /// </summary>
37      public void GetFuncParam(LineSagement_Dto lineSegment)
38         {
39             double x1 = this.Start.X;
40             double y1 = this.Start.Y;
41             double x2 = this.End.X;
42             double y2 = this.End.Y;
43 
44             if (x1 == x2)
45             {
46                 //type=2
47                 this.FunType = LineType_Enum.XX;
48                 this.Params.Add(x1);
49 
50             }
51             else if (y1 == y2)
52             {
53                 //type=1
54                 this.FunType = LineType_Enum.YY;
55                 this.Params.Add(y1);
56             }
57             else
58             {
59                 //type=3
60                 this.FunType = LineType_Enum.XnXYnY;
61                 double a = (y2 - y1) / (x2 - x1);//斜率
62                 double b = y1 - (x1 * ((y2 - y1) / (x2 - x1)));//與Y軸的交點
63                 this.Params.Add(a);
64                 this.Params.Add(b);
65             }
66 
67         }
68 }
線段

第四步:創建線段的型別列舉

 1 /// <summary>
 2 /// 線段的型別
 3 /// </summary>
 4  public enum LineType_Enum
 5  {
 6      /// <summary>
 7      /// 豎線
 8      /// </summary>
 9      XX,
10      /// <summary>
11      /// 橫線
12      /// </summary>
13      YY,
14      /// <summary>
15      /// 斜線
16      /// </summary>
17      XnXYnY
18 }
View Code

第五步:在多邊形類中增加沖突檢測方法

  1 /// <summary>
  2 /// 多邊形沖突檢測
  3 /// </summary>
  4 public bool CheckIfInArea(Area_Dto area)
  5 {
  6     if (area.LineSagements == null)
  7     {
  8         return true;
  9     }
 10     //若子點有在父外的則結束
 11     foreach (Point_Dto point in this.Points)
 12     {
 13         if (!point.CheckIfInArea(area))
 14             return false;
 15     }
 16     //若父點有在子內的則結束
 17     foreach (Point_Dto point in area.Points)
 18     {
 19         if (point.CheckIfInChildArea(this))
 20             return false;
 21     }
 22     //所有子線段與父線段沒有相交則不沖突
 23     if (WhetherPolygonIntersection(area))
 24     {
 25         foreach (LineSagement_Dto edg in this.LineSagements)
 26         {
 27             if (edg.Intersection.Any())
 28             {
 29                 if (edg.FunType == LineType_Enum.XX)
 30                 {
 31                     List<Point_Dto> jiaodainList = edg.Intersection.OrderBy(m => m.Y).ToList();
 32                     for (int i = 0; i < jiaodainList.Count - 1; i++)
 33                     {
 34                         Point_Dto start = jiaodainList[i];
 35                         Point_Dto end = jiaodainList[i + 1];
 36                         Point_Dto z = new Point_Dto(start.X, start.Y + ((end.Y - start.Y) / 2));
 37                         if (z.CheckIfInArea(area))
 38                         {
 39                             continue;
 40                         }
 41                         else
 42                         {
 43                             return false;
 44                         }
 45                     }
 46                 }
 47                 else if (edg.FunType == LineType_Enum.YY)
 48                 {
 49                     List<Point_Dto> jiaodainList = edg.Intersection.OrderBy(m => m.X).ToList();
 50                     for (int i = 0; i < jiaodainList.Count - 1; i++)
 51                     {
 52                         Point_Dto start = jiaodainList[i];
 53                         Point_Dto end = jiaodainList[i + 1];
 54                         Point_Dto z = new Point_Dto(start.X + ((end.X - start.X) / 2), start.Y);
 55                         if (z.CheckIfInArea(area))
 56                         {
 57                             continue;
 58                         }
 59                         else
 60                         {
 61                             return false;
 62                         }
 63                     }
 64                 }
 65                 else if (edg.FunType == LineType_Enum.XnXYnY)
 66                 {
 67                     if (edg.Start.Y <= edg.End.Y)
 68                     {
 69                         List<Point_Dto> jiaodainList = edg.Intersection.OrderBy(m => m.X).ThenBy(m => m.Y).ToList();
 70                         for (int i = 0; i < jiaodainList.Count - 1; i++)
 71                         {
 72                             Point_Dto start = jiaodainList[i];
 73                             Point_Dto end = jiaodainList[i + 1];
 74                             Point_Dto z = new Point_Dto(start.X + ((end.X - start.X) / 2), start.Y + ((end.Y - start.Y) / 2));
 75                             if (z.CheckIfInArea(area))
 76                             {
 77                                 continue;
 78                             }
 79                             else
 80                             {
 81                                 return false;
 82                             }
 83                         }
 84                     }
 85                     else
 86                     {
 87                         List<Point_Dto> jiaodainList = edg.Intersection.OrderBy(m => m.X).ThenByDescending(m => m.Y).ToList();
 88                         for (int i = 0; i < jiaodainList.Count - 1; i++)
 89                         {
 90                             Point_Dto start = jiaodainList[i];
 91                             Point_Dto end = jiaodainList[i + 1];
 92                             Point_Dto z = new Point_Dto(start.X + ((end.X - start.X) / 2), start.Y - ((start.Y - end.Y) / 2));
 93                             if (z.CheckIfInArea(area))
 94                             {
 95                                 continue;
 96                             }
 97                             else
 98                             {
 99                                 return false;
100                             }
101                         }
102                     }
103                 }
104             }
105         }
106     }
107     else
108     {
109         return true;
110     }
111     return true;
112 }
多邊形沖突檢測

第六步:在點的類中增加點與線段關系的判斷方法

 1 /// <summary>
 2 /// 此點向右引出的射線是否穿過sagement
 3 /// 穿過的定義:
 4 ///     此點在sagement的頂點上
 5 ///     此點在sagement上
 6 ///     此點不符合以上兩種情況且此點引出的射線穿過sagement
 7 /// </summary>
 8 /// <param name="sagement"></param>
 9 /// <returns>True:穿過線段 False:沒有穿過線段</returns>
10 public PointWithLineSagementState_Enum CheckPointInLineSagement(LineSagement_Dto sagement)
11 {
12     double px = this.X;
13     double py = this.Y;
14     //bool flag = false;
15 
16 
17     Point_Dto pi = sagement.Start;
18     Point_Dto pj = sagement.End;
19     double sx = pi.X; double sy = pi.Y;
20     double tx = pj.X; double ty = pj.Y;
21 
22     //點與線段頂點重合
23     bool psTf = (px == sx && py == sy);
24     bool ptTf = (px == tx && py == ty);
25     if (psTf || ptTf)
26     {
27         return PointWithLineSagementState_Enum.VertexOverlap;
28     }
29     switch (sagement.FunType)
30     {
31         case LineType_Enum.XX:
32             if (px == pi.X && ((py <= sy && py >= ty) || (py >= sy && py <= ty)))
33                 return PointWithLineSagementState_Enum.OnLineSagement;
34             break;
35         case LineType_Enum.YY:
36             if (py == pi.Y && ((px >= sx && px <= tx) || (px <= sx && px >= tx)))
37                 return PointWithLineSagementState_Enum.OnLineSagement;
38             break;
39         case LineType_Enum.XnXYnY:
40         default:
41             break;
42     }
43     //判斷線段端點是否在射線兩側
44     if ((sy < py && ty >= py) || (sy >= py && ty < py))
45     {
46         //線段上與射線Y坐標相同的點的X坐標
47         double x = sx + (py - sy) * (tx - sx) / (ty - sy);
48         //點在線段上
49         if (x == px)
50         {
51             return PointWithLineSagementState_Enum.OnLineSagement;
52         }
53         //射線穿過線段
54         if (x > px)
55         {
56             return PointWithLineSagementState_Enum.Cross;
57         }
58     }
59     return PointWithLineSagementState_Enum.UnCross;
60 }
61 
62 /// <summary>
63 /// 點線的關系
64 /// </summary>
65 public enum PointWithLineSagementState_Enum
66 {
67     /// <summary>
68     /// 頂點重合
69     /// </summary>
70     VertexOverlap,
71     /// <summary>
72     /// 相交
73     /// </summary>
74     Cross,
75     /// <summary>
76     /// 不相交
77     /// </summary>
78     UnCross,
79     /// <summary>
80     /// 在線段上
81     /// </summary>
82     OnLineSagement
83 }
點與線段關系的判斷

第七步:在點的類中實作子多邊形的點是否在父多邊形內的判斷方法

 1 /// <summary>
 2 /// 子多邊形的點是否在父多邊形內
 3 /// </summary>
 4 /// <param name="theArea">父多邊形</param>
 5 /// <param name="vertexOverlap">當頂點重合時,是否算在圖形內. 默認是算的</param>
 6 /// <returns></returns>
 7 public bool CheckIfInArea(Area_Dto theArea)
 8 {
 9     int cnt = 0;
10     foreach (LineSagement_Dto lineSagement in theArea.LineSagements)
11     {
12         switch (CheckPointInLineSagement(lineSagement))
13         {
14             case PointWithLineSagementState_Enum.Cross:
15                 cnt += 1;
16                 break;
17             case PointWithLineSagementState_Enum.OnLineSagement:
18                 return true;
19             case PointWithLineSagementState_Enum.VertexOverlap:
20                 return true;
21             case PointWithLineSagementState_Enum.UnCross:
22             default:
23                 break;
24         }
25     }
26     //射線穿過多邊形邊界的次數為奇數時點在多邊形內
27     if (cnt % 2 == 1)
28     {
29         return true;//點在多邊形內
30     }
31     else
32     {
33         return false;//點不在多邊形內
34     }
35 }
子多邊形的點是否在父多邊形內

第八步:在點的類中實作父多邊形的點是否在子多邊形內的判斷方法

 1 /// <summary>
 2 /// 父多邊形的點是否在子多邊形內
 3 /// </summary>
 4 /// <param name="theArea"></param>
 5 /// <returns></returns>
 6 public bool CheckIfInChildArea(Area_Dto theArea)
 7 {
 8     int cnt = 0;
 9     foreach (LineSagement_Dto lineSagement in theArea.LineSagements)
10     {
11         switch (CheckPointInLineSagement(lineSagement))
12         {
13             case PointWithLineSagementState_Enum.Cross:
14                 cnt += 1;
15                 break;
16             case PointWithLineSagementState_Enum.OnLineSagement:
17                 return false;
18             case PointWithLineSagementState_Enum.VertexOverlap:
19                 return false;
20             case PointWithLineSagementState_Enum.UnCross:
21             default:
22                 break;
23         }
24     }
25     //射線穿過多邊形邊界的次數為奇數時點在多邊形內
26     if (cnt % 2 == 1)
27     {
28         return true;//點在多邊形內
29     }
30     else
31     {
32         return false;//點不在多邊形內
33     }
34 }
父多邊形的點是否在子多邊形內

第九步:在多邊形的類中實作多邊形自身的線段是否與另外一個多邊形的所有線段相交的方法

  1  /// <summary>
  2 /// 線段是否與多邊形的所有線段有相交
  3 /// True:是
  4 /// False:否
  5 /// </summary>
  6 public bool WhetherPolygonIntersection(Area_Dto father)
  7 {
  8     List<LineSagement_Dto> childEdgeXfatherEdge_List = new List<LineSagement_Dto>();
  9     foreach (LineSagement_Dto edg in this.LineSagements)
 10     {
 11         Point_Dto a = edg.Start;
 12         Point_Dto b = edg.End;
 13         foreach (LineSagement_Dto fatherEdge in father.LineSagements)
 14         {
 15             Point_Dto c = fatherEdge.Start;
 16             Point_Dto d = fatherEdge.End;
 17 
 18             double denominator = (b.Y - a.Y) * (d.X - c.X) - (a.X - b.X) * (c.Y - d.Y);
 19             // 如果分母為0 則平行或共線, 不相交
 20             if (denominator == 0)
 21             {
 22                 //豎線
 23                 if (edg.FunType == LineType_Enum.XX)
 24                 {
 25                     //共線
 26                     if (edg.Start.X == fatherEdge.Start.X)
 27                     {
 28                         //不重疊
 29                         if (b.Y > c.Y || a.Y < d.Y)
 30                         {
 31                             continue;
 32                         }
 33                         //完全重疊
 34                         if (a.Y == c.Y && b.Y == d.Y)
 35                         {
 36                             continue;
 37                         }
 38                         //上跨立(包含兩線相接)
 39                         if (a.Y > c.Y && b.Y <= c.Y && b.Y >= d.Y)
 40                         {
 41                             edg.Intersection.Add(c);
 42                             continue;
 43                         }
 44                         //下跨立(包含兩線相接)
 45                         if (a.Y <= c.Y && a.Y >= d.Y && b.Y < d.Y)
 46                         {
 47                             edg.Intersection.Add(d);
 48                             continue;
 49                         }
 50                         //父包子
 51                         if (c.Y >= a.Y && d.Y <= b.Y)
 52                         {
 53                             continue;
 54                         }
 55                         //子包父
 56                         if (a.Y >= c.Y && b.Y <= d.Y)
 57                         {
 58                             edg.Intersection.Add(c);
 59                             edg.Intersection.Add(d);
 60                             continue;
 61                         }
 62                     }
 63                     //平行
 64                     else
 65                     {
 66                         continue;
 67                     }
 68                 }
 69 
 70                 //橫線
 71                 else if (edg.FunType == LineType_Enum.YY)
 72                 {
 73                     //共線
 74                     if (edg.Start.Y == fatherEdge.Start.Y)
 75                     {
 76                         //不重疊
 77                         if (b.X < c.X || a.X > d.X)
 78                         {
 79                             continue;
 80                         }
 81                         //完全重疊
 82                         if (a.X == c.X && b.X == d.X)
 83                         {
 84                             continue;
 85                         }
 86                         //左跨立(包含兩線相接)
 87                         if (a.X < c.X && b.X >= c.X && b.X <= d.X)
 88                         {
 89                             edg.Intersection.Add(c);
 90                             continue;
 91                         }
 92                         //右跨立(包含兩線相接)
 93                         if (b.X > d.X && a.X >= c.X && a.X <= d.X)
 94                         {
 95                             edg.Intersection.Add(d);
 96                             continue;
 97                         }
 98                         //父包子
 99                         if (c.X <= a.X && d.X >= b.X)
100                         {
101                             continue;
102                         }
103                         //子包父
104                         if (a.X <= c.X && b.X >= d.X)
105                         {
106                             edg.Intersection.Add(c);
107                             edg.Intersection.Add(d);
108                             continue;
109                         }
110                     }
111                     //平行
112                     else
113                     {
114                         continue;
115                     }
116                 }
117                 //斜線
118                 else if (edg.FunType == LineType_Enum.XnXYnY)
119                 {
120                     //共線
121                     if (edg.Params.First().Equals(fatherEdge.Params.First()) && edg.Params.Last().Equals(fatherEdge.Params.Last()))
122                     {
123                         //不重疊
124                         if ((a.X < c.X && b.X < c.X)
125                             || (a.X > d.X && b.X > d.X))
126                         {
127                             continue;
128                         }
129                         //完全重疊
130                         if (a.X == c.X && a.Y == c.Y && b.X == d.X && b.Y == d.Y)
131                         {
132                             continue;
133                         }
134                         //跨立(包含兩線相接)
135                         if (a.X < c.X && b.X >= c.X && b.X <= d.X)
136                         {
137                             edg.Intersection.Add(c);
138                             continue;
139                         }
140                         //跨立(包含兩線相接)
141                         if (a.X >= c.X && a.X <= d.X && b.X > d.X)
142                         {
143                             edg.Intersection.Add(d);
144                             continue;
145                         }
146                         //父包子
147                         if (a.X >= c.X && a.X <= d.X && b.X >= c.X && b.X <= d.X)
148                         {
149                             continue;
150                         }
151                         //子包父
152                         if (a.X <= c.X && b.X >= d.X)
153                         {
154                             edg.Intersection.Add(c);
155                             edg.Intersection.Add(d);
156                             continue;
157                         }
158                     }
159                     //平行
160                     else
161                     {
162                         continue;
163                     }
164                 }
165             }
166             // 線段所在直線的交點坐標 (x , y)
167             double x = ((b.X - a.X) * (d.X - c.X) * (c.Y - a.Y)
168                 + (b.Y - a.Y) * (d.X - c.X) * a.X
169                 - (d.Y - c.Y) * (b.X - a.X) * c.X) / denominator;
170             double y = -((b.Y - a.Y) * (d.Y - c.Y) * (c.X - a.X)
171                 + (b.X - a.X) * (d.Y - c.Y) * a.Y
172                 - (d.X - c.X) * (b.Y - a.Y) * c.Y) / denominator;
173             // 判斷交點是否在兩條線段上
174             if (
175                // 交點在線段1上
176                (x - a.X) * (x - b.X) <= 0 && (y - a.Y) * (y - b.Y) <= 0
177                // 且交點也在線段2上
178                && (x - c.X) * (x - d.X) <= 0 && (y - c.Y) * (y - d.Y) <= 0)
179             {
180                 edg.Intersection.Add(new Point_Dto(x, y));
181             }
182             else
183             {
184                 continue;
185             }
186         }
187     }
188     if (this.LineSagements.Where(m => m.Intersection.Any()).Any())
189     {
190         return true;
191     }
192     else
193     {
194         return false;
195     }
196 }
線段是否與多邊形的所有線段有相交

 

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/288815.html

標籤:C#

上一篇:dotnet OpenXML 讀取 PPT 主序列進入退出強調影片

下一篇:C#中時間相關知識點小結

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • WebAPI簡介

    Web體系結構: 有三個核心:資源(resource),URL(統一資源識別符號)和表示 他們的關系是這樣的:一個資源由一個URL進行標識,HTTP客戶端使用URL定位資源,表示是從資源回傳資料,媒體型別是資源回傳的資料格式。 接下來我們說下HTTP. HTTP協議的系統是一種無狀態的方式,使用請求/ ......

    uj5u.com 2020-09-09 22:07:47 more
  • asp.net core 3.1 入口:Program.cs中的Main函式

    本文分析Program.cs 中Main()函式中代碼的運行順序分析asp.net core程式的啟動,重點不是剖析原始碼,而是理清程式開始時執行的順序。到呼叫了哪些實體,哪些法方。asp.net core 3.1 的程式入口在專案Program.cs檔案里,如下。ususing System; us ......

    uj5u.com 2020-09-09 22:07:49 more
  • asp.net網站作為websocket服務端的應用該如何寫

    最近被websocket的一個問題困擾了很久,有一個需求是在web網站中搭建websocket服務。客戶端通過網頁與服務器建立連接,然后服務器根據ip給客戶端網頁發送資訊。 其實,這個需求并不難,只是剛開始對websocket的內容不太了解。上網搜索了一下,有通過asp.net core 實作的、有 ......

    uj5u.com 2020-09-09 22:08:02 more
  • ASP.NET 開源匯入匯出庫Magicodes.IE Docker中使用

    Magicodes.IE在Docker中使用 更新歷史 2019.02.13 【Nuget】版本更新到2.0.2 【匯入】修復單列匯入的Bug,單元測驗“OneColumnImporter_Test”。問題見(https://github.com/dotnetcore/Magicodes.IE/is ......

    uj5u.com 2020-09-09 22:08:05 more
  • 在webform中使用ajax

    如果你用過Asp.net webform, 說明你也算是.NET 開發的老兵了。WEBform應該是2011 2013左右,當時還用visual studio 2005、 visual studio 2008。后來基本都用的是MVC。 如果是新開發的專案,估計沒人會用webform技術。但是有些舊版 ......

    uj5u.com 2020-09-09 22:08:50 more
  • iis添加asp.net網站,訪問提示:由于擴展配置問題而無法提供您請求的

    今天在iis服務器配置asp.net網站,遇到一個問題,記錄一下: 問題:由于擴展配置問題而無法提供您請求的頁面。如果該頁面是腳本,請添加處理程式。如果應下載檔案,請添加 MIME 映射。 WindowServer2012服務器,添加角色安裝完.netframework和iis之后,運行aspx頁面 ......

    uj5u.com 2020-09-09 22:10:00 more
  • WebAPI-處理架構

    帶著問題去思考,大家好! 問題1:HTTP請求和回傳相應的HTTP回應資訊之間發生了什么? 1:首先是最底層,托管層,位于WebAPI和底層HTTP堆疊之間 2:其次是 訊息處理程式管道層,這里比如日志和快取。OWIN的參考是將訊息處理程式管道的一些功能下移到堆疊下端的OWIN中間件了。 3:控制器處理 ......

    uj5u.com 2020-09-09 22:11:13 more
  • 微信門戶開發框架-使用指導說明書

    微信門戶應用管理系統,采用基于 MVC + Bootstrap + Ajax + Enterprise Library的技術路線,界面層采用Boostrap + Metronic組合的前端框架,資料訪問層支持Oracle、SQLServer、MySQL、PostgreSQL等資料庫。框架以MVC5,... ......

    uj5u.com 2020-09-09 22:15:18 more
  • WebAPI-HTTP編程模型

    帶著問題去思考,大家好!它是什么?它包含什么?它能干什么? 訊息 HTTP編程模型的核心就是訊息抽象,表示為:HttPRequestMessage,HttpResponseMessage.用于客戶端和服務端之間交換請求和回應訊息。 HttpMethod類包含了一組靜態屬性: private stat ......

    uj5u.com 2020-09-09 22:15:23 more
  • 部署WebApi隨筆

    一、跨域 NuGet參考Microsoft.AspNet.WebApi.Cors WebApiConfig.cs中配置: // Web API 配置和服務 config.EnableCors(new EnableCorsAttribute("*", "*", "*")); 二、清除默認回傳XML格式 ......

    uj5u.com 2020-09-09 22:15:48 more
最新发布
  • C#多執行緒學習(二) 如何操縱一個執行緒

    <a href="https://www.cnblogs.com/x-zhi/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2943582/20220801082530.png" alt="" /></...

    uj5u.com 2023-04-19 09:17:20 more
  • C#多執行緒學習(二) 如何操縱一個執行緒

    C#多執行緒學習(二) 如何操縱一個執行緒 執行緒學習第一篇:C#多執行緒學習(一) 多執行緒的相關概念 下面我們就動手來創建一個執行緒,使用Thread類創建執行緒時,只需提供執行緒入口即可。(執行緒入口使程式知道該讓這個執行緒干什么事) 在C#中,執行緒入口是通過ThreadStart代理(delegate)來提供的 ......

    uj5u.com 2023-04-19 09:16:49 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    <a href="https://www.cnblogs.com/huangxincheng/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/214741/20200614104537.png" alt="" /&g...

    uj5u.com 2023-04-18 08:39:04 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    一:背景 1. 講故事 前段時間協助訓練營里的一位朋友分析了一個程式卡死的問題,回過頭來看這個案例比較經典,這篇稍微整理一下供后來者少踩坑吧。 二:WinDbg 分析 1. 為什么會卡死 因為是表單程式,理所當然就是看主執行緒此時正在做什么? 可以用 ~0s ; k 看一下便知。 0:000> k # ......

    uj5u.com 2023-04-18 08:33:10 more
  • SignalR, No Connection with that ID,IIS

    <a href="https://www.cnblogs.com/smartstar/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/u36196.jpg" alt="" /></a>...

    uj5u.com 2023-03-30 17:21:52 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:15:33 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:13:31 more
  • C#遍歷指定檔案夾中所有檔案的3種方法

    <a href="https://www.cnblogs.com/xbhp/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/957602/20230310105611.png" alt="" /></a&...

    uj5u.com 2023-03-27 14:46:55 more
  • C#/VB.NET:如何將PDF轉為PDF/A

    <a href="https://www.cnblogs.com/Carina-baby/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2859233/20220427162558.png" alt="" />...

    uj5u.com 2023-03-27 14:46:35 more
  • 武裝你的WEBAPI-OData聚合查詢

    <a href="https://www.cnblogs.com/podolski/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/616093/20140323000327.png" alt="" /><...

    uj5u.com 2023-03-27 14:46:16 more