如何在vb.net中解决system.OutOfMemoryException错误?

时间:2016-10-10 08:51:00

标签: json memory out-of-memory

我完全坚持这个错误,请帮助我..

我创建了一个json文件,用户可以从开始日期到结束日期进行选择。 所以button1用于生成文件.. 程序顺利,直到我选择一个更大的数据来生成..然后出现这个内存错误..这是我的代码:



  Using writer As JsonWriter = New JsonTextWriter(sw)
                writer.Formatting = Formatting.Indented
                With writer
                    .WriteStartObject()
                    .WritePropertyName("LiveValue")
                    .WriteStartArray()
                    Do



                      
                        liveValue.Time_Stamp = u
                        liveValue.Current = Generator.Next(MyMin_Current, MyMax_Current + 1)
                        liveValue.Voltage = Generator.Next(MyMin_Voltage, MyMax_Voltage + 1)
                        liveValue.Power = liveValue.Current * liveValue.Voltage

                        .WriteStartObject()
                        .WritePropertyName("ID")
                        .WriteValue(i)
                        .WritePropertyName("TimeStamp")
                        .WriteValue(liveValue.Time_Stamp)
                        .WritePropertyName("MotorID")
                        .WriteValue(liveValue.MotorID)
                        .WritePropertyName("Current")
                        .WriteValue(liveValue.Current)
                        .WritePropertyName("Voltage")
                        .WriteValue(liveValue.Voltage)
                        .WritePropertyName("Power")
                        .WriteValue(liveValue.Power)

                        .WriteEndObject()

                        i = i + 1

                        If liveValue.MotorID < 20 Then
                            liveValue.MotorID = liveValue.MotorID + 1
                        Else
                            liveValue.MotorID = 1
                        End If


                        'If endTime > startTime Then
                        '    liveV.Time_Stamp = u.AddMinutes(+1)
                        'Else
                        '    liveV.Time_Stamp = endTime
                        'End If

                        '(Time Stamp) Time changed every 7secs
                        If i = w Then
                            u = u.AddMinutes(+1)
                            w = w + 20
                        End If

                    Loop Until (liveValue.Time_Stamp = endTime)
                    .WriteEndArray()
                    .WriteEnd()






                End With
                file1.WriteLine(sb.ToString)
                pBar.Style = ProgressBarStyle.Continuous
               


            End Using
&#13;
&#13;
&#13; 请帮我解决..谢谢

0 个答案:

没有答案