я в настоящее время пытаюсь увеличить Stack размера для нового тему, так что я могу запустить мой метод ниже без применения выбрасывая StackOverflowException.Создание нового потока для метода
public QuoteResult CalculateRates(TruckDb db, QuoteData data)
{
var result = new QuoteResult
{
Successful = false,
Data = data
};
//...EDIT with code samples
//Floor - 1
var qisg = new QuoteItemSectionGroup
{
SectionGroup = db.SectionGroups.Where(x => x.Name == "Longitudinals" && x.Section == TruckSection.Floor).First(),
StockItem = quoteItem.FloorSpec.Name == "Ali Floor Bakery" || quoteItem.FloorSpec.Name == "Trailer Floor" || quoteItem.FloorSpec.Name == "Use Existing Floor" ? null : quoteItem.BodyType.Name == "Insulated" || quoteItem.BodyType.Name == "Insulated Meat Hanger" ? db.StockItems.Where(x => x.StockCode == "SCH095").First()
: quoteItem.BodyType.Name == "Royal Corrugated" || quoteItem.BodyType.Name == "Royal Smooth Glued" || quoteItem.BodyType.Name == "Royal Smooth Riveted" ||
quoteItem.BodyType.Name == "Royal Tautliner" || quoteItem.BodyType.Name == "Penta Slider Curtain-side" || quoteItem.BodyType.Name == "Bakery Light Weight GRP" ||
quoteItem.BodyType.Name == "Free Flow Bakery Body" || quoteItem.BodyType.Name == "Boardside GRP Body" || quoteItem.BodyType.Name == "Drop Side" || quoteItem.BodyType.Name == "Flat Deck" ? quoteItem.ChassisModel.Longitudinal : null
};
qisg.Quantity = qisg.StockItem == null ? 0 : 2;
qisg.Length = qisg.StockItem == null ? 0 : Math.Round((quoteItem.BodyType.Name == "Royal Corrugated" || quoteItem.BodyType.Name == "Royal Smooth Glued" || quoteItem.BodyType.Name == "Smooth Folded" || quoteItem.BodyType.Name == "Royal Smooth Riveted" || quoteItem.BodyType.Name == "Bakery Light Weight GRP" || quoteItem.BodyType.Name == "Free Flow Bakery Body" || quoteItem.BodyType.Name == "Boardside GRP Body" || quoteItem.BodyType.Name == "Insulated" || quoteItem.BodyType.Name == "Insulated Meat Hanger" || quoteItem.BodyType.Name == "Drop Side" || quoteItem.BodyType.Name == "Flat Deck" ? -0.157
: quoteItem.BodyType.Name == "Penta Slider Curtain-side" ? -0.150 : quoteItem.BodyType.Name == "Royal Tautliner" ? -0.060
: 0) + (quoteItem.ExternalLength/1000), 3);
qisg.Weight = qisg.StockItem == null ? 0 : Math.Round(((double)qisg.Length * (double)qisg.Quantity) * (double)qisg.StockItem.Mass, 3);
qisg.Cost = qisg.StockItem == null ? 0 : Math.Round(((double)qisg.Length * (double)qisg.Quantity) * (double)qisg.StockItem.UnitCost, 2);
if (qisg.StockItem != null)
quoteItem.SectionGroups.Add(qisg);
//Floor - 2
qisg = new QuoteItemSectionGroup
{
SectionGroup = db.SectionGroups.Where(x => x.Name == "Cross Member" && x.Section == TruckSection.Floor).First(),
StockItem = quoteItem.FloorSpec.Name == "Ali Floor Bakery" || quoteItem.FloorSpec.Name == "Trailer Floor" || quoteItem.FloorSpec.Name == "Use Existing Floor" ? null : quoteItem.BodyType.Name == "Insulated" || quoteItem.BodyType.Name == "Insulated Meat Hanger" || quoteItem.BodyType.Name == "Penta Slider Curtain-side" ? db.StockItems.Where(x => x.StockCode == "SCH095").First()
: quoteItem.BodyType.Name == "Royal Corrugated" || quoteItem.BodyType.Name == "Royal Smooth Glued" || quoteItem.BodyType.Name == "Royal Smooth Riveted" || quoteItem.BodyType.Name == "Royal Tautliner" || quoteItem.BodyType.Name == "Bakery Light Weight GRP" ||
quoteItem.BodyType.Name == "Free Flow Bakery Body" || quoteItem.BodyType.Name == "Boardside GRP Body" || quoteItem.BodyType.Name == "Drop Side" || quoteItem.BodyType.Name == "Flat Deck" ? db.StockItems.Where(x => x.StockCode == "SCH075").First() : null
};
qisg.Quantity = qisg.StockItem == null ? 0 : Math.Floor(quoteItem.BodyType.Name == "Insulated" || quoteItem.BodyType.Name == "Insulated Meat Hanger" || quoteItem.BodyType.Name == "Royal Corrugated"
|| quoteItem.BodyType.Name == "Royal Smooth Glued" || quoteItem.BodyType.Name == "Royal Smooth Riveted" || quoteItem.BodyType.Name == "Royal Tautliner"
|| quoteItem.BodyType.Name == "Bakery Light Weight GRP" || quoteItem.BodyType.Name == "Free Flow Bakery Body" || quoteItem.BodyType.Name == "Boardside GRP Body" || quoteItem.BodyType.Name == "Drop Side" || quoteItem.BodyType.Name == "Flat Deck" ? ((quoteItem.ExternalLength/quoteItem.FloorChannelSpacing.Amount) + 2)
: quoteItem.BodyType.Name == "Penta Slider Curtain-side" ? (quoteItem.ExternalLength/quoteItem.FloorChannelSpacing.Amount) : 0);
qisg.Length = qisg.StockItem == null ? 0 : Math.Round((quoteItem.BodyType.Name == "Royal Corrugated" || quoteItem.BodyType.Name == "Royal Smooth Glued" || quoteItem.BodyType.Name == "Smooth Folded" || quoteItem.BodyType.Name == "Royal Smooth Riveted" || quoteItem.BodyType.Name == "Bakery Light Weight GRP" || quoteItem.BodyType.Name == "Free Flow Bakery Body" || quoteItem.BodyType.Name == "Boardside GRP Body" || quoteItem.BodyType.Name == "Insulated" || quoteItem.BodyType.Name == "Insulated Meat Hanger" || quoteItem.BodyType.Name == "Drop Side" || quoteItem.BodyType.Name == "Flat Deck" ? -0.020
: quoteItem.BodyType.Name == "Penta Slider Curtain-side" ? -0.070 : quoteItem.BodyType.Name == "Royal Tautliner" ? -0.030
: 0) + (quoteItem.ExternalWidth/1000), 3);
qisg.Weight = qisg.StockItem == null ? 0 : Math.Round(((double)qisg.Length * (double)qisg.Quantity) * (double)qisg.StockItem.Mass, 3);
qisg.Cost = qisg.StockItem == null ? 0 : Math.Round(((double)qisg.Length * (double)qisg.Quantity) * (double)qisg.StockItem.UnitCost, 2);
if (qisg.StockItem != null)
quoteItem.SectionGroups.Add(qisg);
//It continues on like this with about 80 more blocks of code like the above samples
result.Successful = true;
return result;
}
Я попытался кодирования в несколько способов, которыми люди предложенных в других вопросах, но я не могу понять, как использовать мой метод в новом потоке.
Вот одна из моих попыток:
void NewThread(QuoteResult result)
{
const int stackSize = 0x400000;
var T = new Thread(CalculateRates, stackSize);
T.Start();
T.Join();
}
Но, выкидывает ошибку:
The best overloaded method match for 'System.Threading.Thread.Thread(System.Threading.ParameterizedThreadStart, int)' has some invalid arguments
Как вы можете ясно видеть, я понятия не имею, что я делаю или как создайте новый поток для моего метода, поэтому я жду много критики. Если кому-либо понадобится больше образцов кода или информации, пожалуйста, не стесняйтесь спрашивать.
Спасибо за любую помощь заранее!
И жаль, если это смутное вопрос
EDIT
методы, которые также используют CalculateRates метод:
public QuoteResult GetQuote(QuoteData Data)
{
using (TruckDb db = new TruckDb())
{
var result = CalculateRates(db, Data);
return result;
}
}
И
public bool FinalizeQuote(QuoteResult quoteResult)
{
using (TruckDb db = new TruckDb())
{
var calcResult = CalculateRates(db, quoteResult.Data);
//Make sure that result still gives the same amount and that they where successful calculations
if (calcResult.TotalAmount != quoteResult.TotalAmount || !quoteResult.Successful || !calcResult.Successful)
return false;
var company = db.Companies.Where(x => x.Name == "Test Co.").FirstOrDefault();
if (company == null)
company = db.Companies.Add(new Company { Name = "Test Co." });
var rep = company.Represetatives.Where(x => x.Name == "Person").FirstOrDefault();
if (rep == null)
{
rep = new Represetative { Name = "Person" };
company.Represetatives.Add(rep);
}
var quote = new Quote { Date = DateTime.Now, QuoteNumber = DateTime.Now.ToString() };
rep.Quotes.Add(quote);
quote.Items.Add(calcResult.QuoteItem);
db.SaveChanges();
}
return true;
}
Имея 'StackOverflowException' может означать, что вы должны иметь другую мысль о своем решении. Можете ли вы показать нам какой-то код? –
@JeroenvanLangen Да, я скоро поправлюсь :) – CareTaker22
@JeroenvanLangen Я добавил примеры кода – CareTaker22