2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Text ;
5
+ using System . Threading ;
5
6
using System . Threading . Tasks ;
6
7
using FreneticUtilities . FreneticToolkit ;
7
8
using Discord ;
@@ -41,15 +42,16 @@ public struct InternalData
41
42
public bool HasSendTaskActive ;
42
43
43
44
/// <summary>The internal method that gets scheduled for later when scheduling a delayed send task.</summary>
44
- public void WaitingTask ( )
45
+ public static void WaitingTask ( object _self )
45
46
{
47
+ MessageBulker self = _self as MessageBulker ;
46
48
Task . Delay ( 400 ) . Wait ( ) ;
47
- lock ( Locker )
49
+ lock ( self . Internal . Locker )
48
50
{
49
- HasSendTaskActive = false ;
51
+ self . Internal . HasSendTaskActive = false ;
50
52
try
51
53
{
52
- DoSend ( ) ;
54
+ self . Internal . DoSend ( ) ;
53
55
}
54
56
catch ( Exception ex )
55
57
{
@@ -69,8 +71,7 @@ public void ScheduleTask()
69
71
}
70
72
HasSendTaskActive = true ;
71
73
}
72
- MessageBulker self = Self ; // C# gets iffy around structs and tasks, don't remove this
73
- Task . Factory . StartNew ( ( ) => self . Internal . WaitingTask ) ;
74
+ new Thread ( new ParameterizedThreadStart ( WaitingTask ) ) . Start ( Self ) ; // Not using tasks due to C# being janky around tasks with structs
74
75
}
75
76
76
77
/// <summary>The internal direct send-to-channel message. Do not call directly, use <see cref="Send(string)"/>.</summary>
@@ -104,7 +105,7 @@ public void DoSend()
104
105
LastSentTicks = Environment . TickCount64 ;
105
106
}
106
107
MessageBulker self = Self ;
107
- Task . Factory . StartNew ( ( ) =>
108
+ Task . Factory . StartNew ( ( ) => // TODO: Does this need to be swapped to Thread as well?
108
109
{
109
110
try
110
111
{
@@ -136,7 +137,7 @@ public void Send(string text)
136
137
lock ( Internal . Locker )
137
138
{
138
139
Internal . ToSend . Enqueue ( text ) ;
139
- if ( ! Internal . HasSendTaskActive && ( Internal . LastSentTicks <= 0 || Internal . LastSentTicks + 500 < Environment . TickCount64 || text . Length > 1800 ) )
140
+ if ( ! Internal . HasSendTaskActive && ( Internal . LastSentTicks <= 0 || Internal . LastSentTicks + 1500 < Environment . TickCount64 || text . Length > 1800 ) )
140
141
{
141
142
Internal . DoSend ( ) ;
142
143
}
0 commit comments